The solution is just to clamp
value
to max_value
:
func _on_Timer_timeout():
if value < max_value:
value = clamp(value + 1, 0, max_value)
$Label.text = "ST " + str(value) + " / " + str(max_value)
I do think you need to reconsider your if
conditional that I mentioned in the comment above - I don't think it's doing what you think it's doing. Global.damage * delta
will be a small number since delta
is usually very small (think > 0.2) so value -= Global.damage
could end up negative.