Weird problem with creating stamina bar for sprinting (top-down)

In the pictures, you can see the code which creates sprinting. The stamina timer counts down from twelve, and stops whenever the player is not sprinting. If the counter gets to zero, it should stop the player from sprinting. However, if you start running while you still have stamina and don’t stop holding down lshift when the timer reaches zero, you can KEEP sprinting which is not supposed to happen. For some reason, you have to stop sprinting once the timer reaches zero and in order for the game to realize you are out of stamina! In other words, you can run infinitely and you only can’t run if you try to run when your stamina is starting at zero! Any solutions so that the game stops you sprinting if the timer is zero, no matter what?

In the last event where you have ‘LShift key is NOT pressed’, add an OR condition so it looks like this:


  • LShift key is NOT pressed
  • The text of ‘staminatext’ is = 0

That way the player can’t sprint when not holding Shift or when the stamina runs out.

Also, consider using a number variable for stamina, instead of text.

1 Like

There is so much to unpack with the logic you provided… anyway, below is a quick example using the online editor.

You should be able to adapt it using your logic.

Test - Arrow to move, LCtrl to sprint

.json 30 day expiry
Pastebin - No expiry

Thanks, this worked!

Hi, i want to put this into my game too but I don’t figure out where that “stamina recover” comes from, is it a variable? An object behavior?