if the health increase is a one time only also connect the body_exited
signal
#Healthbar.gd
extends Control
var health = 100
var health_max = 100
func _ready():
$bleed_timer.wait_time = 1 #second
$bleed_timer.start()
func life_change(amt):
health += amt
#prevent health from going over 100 and under 0
health = clamp(health, 0, health_max)
$ProgressBar.value = health
func _on_bleed_timer_timeout():
life_change(-5)
#Player.gd
func _on_interactionarea_body_entered(body):
if body.name == "blood pack":
$Camera2D/healthbar/bleed_timer.stop()
$Camera2D/healthbar.life_change(20)
func _on_interactionarea_body_exited(body):
if body.name == "blood pack":
$Camera2D/healthbar/bleed_timer.start()
Tips for the future
Don't use _process
unless you need a reoccurring action
Do use reactive actions instead (something happens because something happened)
Don't update visuals and variables separately
Do change variables first then reflect that change visually
Don't always rely on using $node or get_node() everywhere
Do assign them to variables instead in cases where you decide to rename nodes you won't have to refactor your entire code, only the line with the assignment
Example
var health_bar = $Camera2D/healthbar
var bleed_timer = $bleed_timer