Health won’t change[SOLVED]

Hi!
Currently, I’m having some trouble with my character’s health
They are supposed to have 3 lives and it goes down each time they die until 0. And the hearts change accordingly. But currently, even if the character dies, nothing happens, the lives don’t change at all
Here’s the code I have for this so far



Any help is appreciated! :]

Edit: I just checked by also manually changing the variable to see if the hearts would change and they didn’t so it’s a problem with that
Edit: If character dies twice, it’ll go down 2 hearts, but if only once, it does nothing
Edit: Turns out I just placed an object twice and the code’s fine- thanks for all the replies though!

What does Player_boy.Health start off at? How is it set?

It starts at 3, and what do you mean how is it set?

Please verify that the objects on the scene are NewSprite2, NewSprite3 and NewSprite4. I’ve made that mistake by duplicating objects instead of adding different objects.

1 Like

I just have to say, this is a very cumbersome way of making a healthbar. The bar should just be a single tiled sprite, and when player’s health changes you can just change the width of the bar. So if you have a 16x16 heart, your action would be like this:

change the width of healthBar to Player_boy.Health * 16

This is much easier to deal with than redundant copies of objects and events

Do you set it in events, or as a default value in the object editor?

i was gonna say its an instance variable issue but looking at the script it says each sprite of the health bar is different, i do not recommend that unless you want…(remembers spaghetti code doesnt exist) now i dont know what to say besides try using a kill collider and spawn point sprites for your position based respawning system

anytime i used duplicated objects i would have an id number variable added to each instance, this only worked for me once though when i was creating cyber city