WHILE BUTTON() would work only if you're pressing the designated button BEFORE the loop starts. Using REPEAT won't help, so try to sepparate the logic of the game from the functionality of the main loop.
Just as @V360 shows.
Don't work because any Sprite function should be used AFTER SPSET, not BEFORE it. Because you first need too tell the engine that a sprite will be used before telling the engine to manipulate it.