How to make enemy damage a player and decrease the player's health bar?

Hello! I’m making a game where you shoot enemies, and when they damage you, your health bar decreases. The thing is, I’m new to Godot, so I’ve been watching lots of different tutorials. I tried using two different tutorials for this function, but it’s not working. I don’t know if the problem is in the masks and layers or the general code. Please help, I’m stuck!! T0T

here is my player code:


this is my health bar code:

and my enemy code:

I woul appreciate any help, please!!

Make a onready var for the TextureProgressBar in the enemy script and add the health var in the health bar script outside of the function. Select the Area2D in the enemy, go from inspector to node, then connect the signal body_entered to the script. To decrease the player’s health in the enemy’s script, write the line ‘’‘textureprogressbar.health-=1’‘’ I hope this works.

It’s not working T0T
Here is how my code is looking now, I’m getting extremely confused.

enemy:


healthbar:

player:


Do you have the right node path to the healthbar node? Maybe that is whats wrong with it?

I found a tutorial that helped me, even so, I appreciate the help!!

1 Like