Having some serious trouble

Maybe you were using the serial monitor, and your sketch had some big delays that allowed the function to work as you thought it should.
Remember, serial comms are slowwwwwww.