[Solved] While loop crashes Preview

I am trying to have a variable go up when you walk and then go back down when you stop, as a way to monitor how loud you are, however i don’t just want to do a “Set variable to” because then the variable will snap from 0 to 2 in an instant and i want it to go up one step at a time. I did this through a while loop that first checks if you are moving to the right (i will do left later in a similar script) then checks for if you’re not jumping or crouching because those will have louder volymes. If all that is true it adds +1 to a variable every 0.2 secounds and stops once you hit 2. the thing is that when i preview the game it freezes the instant i press right, i’ve considered that it might be checking something rapidly over and over forever which could be hard on the computor. But really the max amount of times that this loop will ever play is two because the variable keeps going up by one until it hits two and the loop even has a 0.2 secound wait inside it so the loop wouldn’t even play that fast if it did repeat forever! Here’s my code:

Please help!

While loops stop the event sheet from proceeding until they are completed.

I don’t think your event will ever work because the wait cannot proceed since the event sheet never proceeds. You have basically caused an endless loop/logic fault.

Your described goal sounds better set up either for a normal event with a timer. Or if you are using a side acrolling/platformer behavior, add a point on your characters foot and add to your variable every time it is inside of a platform.

Thanks! I managed to fix the issue with your explaination! :grin: