Infinite loop detected

What I’m trying to do is get a value for how long the player has spent in the air, so I can later create a damage system based off of that. Right now, I have it so whenever a jump is detected, a while loop will start with a condition that the player is falling. While the player is falling I am constantly adding to that var “timeInAir”.

However, when I test this out I’m getting an infinite loop detected error.

I’m not sure why this is happening, since how I am thinking this would play out is the player would jump, the var would add until the player eventually hits the ground and the while loop is stopped. Maybe my approach of this is wrong? But I’m not sure. Any help would be appreciated. Thanks!

Thats not how while loops are meant to work. A while loop like all loops runs between frames and it will fire exremely quickly. Thats the simplest i can think to explain it. What you will want to do instead is to create either a custom loop which goes something like custom event, check is falling?, if true increment variable, delay, call custom event again. The alternative would be to ise a timer where you would on begin fallin start timer and loop it until your not falling anymore.