moving the read(0) lone below the loop that shifts values seemed to get rid of the error, and x=0 before a loop helps as well, you were drawing the graph more and more to the right after each lua tick, which quickly got it out of the screen. Hope it helps