Stamina regen timer not working

@onready var stamreg_timer = $"Stam Timer"

var regen : int = 0

# Checks if pressing Shift/Run button.
	if Input.is_action_pressed("Run") and input_dir.y < 0 and can_run == true:
		run_speed = 1.75
		stamina -= ceil(2 * delta)
		print("Stamina: " + str(stamina))
	else:
		run_speed = 1.0
		stamreg_timer.start()
		regen = 0

func _stamina_reg_timer():
	regen = 1
	print("Regenerate stamina")

For some reason a my timer is not working. When the player stops holding the run button the timer should start, but no matter what the timer will just never start.


Timer

Hi,

Either it does not start, or it is restarting every frame. start will reset the timer if it’s running already, which might be your issue.
Try adding a print like this, and if it’s triggered every frame, that would confirm my guess:

else:
    run_speed = 1.0
    print('timer start')
    stamreg_timer.start()
    regen = 0

One way you could fix that is just checking that the timer is not running already:

if stamreg_timer.is_stopped():
    stamreg_timer.start()