I finally found what the problem is!
I downloaded your project and messed around a bit. I noticed that your print(new_health)
statement in the func _on_Player_health_changed(new_health)
function printed out the same number several times before crashing and I figured that there's got to be a loop in there somewhere. Then I figured out that you have connected the wrong node to the health_changed
signal! You had connected the signal to the Player
node, when you should have connected it to the LifeBar
node. Go to your Player
node, disconnect the signal and reconnect it to LifeBar
.
The func _on_Player_health_changed(new_health)
will appear in the LifeBar
node's script, where you can place the self.value = new_health
logic.
By the way, I noticed that your Player scene has the Player.gd script attached to it, and the Player node in the main scene also has the same script attached to it! Why is that? You do not need to have the same script twice. Also, remember to disconnect the signal both from the Player
scene and the Player
node in the Main
scene.
Please upvote mark this answer as best, so that others can find it useful too!