Stamina Bar Regen Not Working as Intended

Godot Version

Hey! I’m currently just messing around in Godot trying to get my bearings as I’m entirely new to Gamedev and coding as a whole. I’m currently working on a sprint mechanic and it’s not quite working as I want it to. (script attached)

What I want to happen: Press shift while holding a direction key to sprint. When sprinting stops (let go of shift), a 1.5 sec timer starts. When this timer times out, the stamina bar begins to regen. (everything is working so far) The problem is that when after all of this, if I sprint again and then let go of the sprint key, the timer no longer prevents the stamina bar from regenning for 1.5 seconds and it instead starts going up immediately. This is probably an easy fix with the timer, but I’m just a little lost.

Thanks so much!

I think you forgot to set the START_REGEN to false, after sprint released, set this false

Try this

if Input.is_action_just_released("sprint"):
	START_REGEN = false

I believe the problem stems from START_REGEN never being set to false - it remains true forever. And so line 51 runs, and ends up increasing stamina much more than line 44 decreases stamina.

Think about when you want to reset the START_REGEN to false. Probably when you start sprinting again, right?