Sensing key pressed - getting stuck, or variable not resetting

I have a student creating an Asteroids style game.

His issue is that his WASD controls are getting stuck. His code seems logical. It isn't happening on my machine, so I can't seem to reproduce it. I am curious why it might be happening.

He is running Google Chrome on Windows 10.

His project is here:

Basically hitting the green flag (even multiple times) will keep reading his character as moving left. Pressing the left button ('A' key) will reset this. It just gets stuck moving left.

Pressing up or down ('W' and 'S' keys) will override this somehow and move vertically, while pausing this errant move left.

I can't find any errors in his code.
The reason he used a separate loop and the vertical/horizontal variables is because he was having lag with one large loop. Separating it this way greatly cut down on his lag.

Again, I can't seem to reproduce it, but I just feel bad for this student. He is one of my more advanced students and has had a lot of issues with Clones lagging (posted about his other project a few days ago with lots of lag) and now he is getting stuck or having variables not reset correctly. Since I can't reproduce it I can't figure out why it is happening.

Thank you,

If you say
untitled script pic
then after it does whatever it does, you're still in a FOREVER loop and the key is still pressed. (Computers are faster than people.) Instead your student should say

I would actually make a separate script for each key:

You may not need the WAIT UNTIL in that case, but it doesn't hurt... Unless of course you want the key to be repeating.

Oh my gosh, thank you so much. I never realized that the "When ___ key pressed" hat was waiting until its script finished to start sensing again. I thought there was a fixed time delay (like 0.01-0.1 second) in between sensing separate events of button presses. I didn't use this hat often. My students would often use it with loops and broadcast while holding the key down and it would end up stumbling all over itself, as it interacted with other bits of code.

The "when ___ key pressed" and then waiting until not key pressed will be SOOOO useful.

Thank you!

I can't believe I never realized this. I really did think it was just a fixed time delay in between sensing single events of the button being pressed.

We live to serve. :~)