[SOLVED] Player healthbar not respawning

when i start my game, my healthbar is fine then when i restart, my players healthbar is gone and wont appear, i tried everything, whats the idea


How do you restart your game?

through the script named PlayerHealth, which is given to the player clone that u play with, when his health is 0, a screen shows up and says press r to restart

I can’t find where or how you restart the game or entity in that script.
If you use reset() for that i don’t think reset() is working that way but maybe i’m wrong.

Also i think this line

    this.entity.collision.on('collisionstart', this.onCollisionStart, this);

should be in the initialize function and not in the update function.

1 Like

so the spawner script, spawns the player, then when he dies, the spawner turns off, this when you press r, the spawner turns back on, so when it turns back on, the player spawns again, and ill try that

Have you found a solution yet?

no, not yet

I could help if you want.

But I’m not seeing the problem here. I’m sure @Albertos can help you.

when you click restart, your healthbar doesnt reapear, any ideas? and yea hes helping me

Well, once I die I get an error:


This happens because player 2 is not found anymore…


Are you deleting referenced entitys?

yes, but my problem is that when you respawn, your bar does not show

Ok. So where in the hierarchy is the healthbar located and with wich scripts do you interact with it?

its solved now, my Player prefab did not have any scripts attached, i had the scripts like the healthbar given to the cloned Player which was messing up the Healthbar when you had to respawn,

Solution: i gave the PreFab the HealthBar script and changed the name of the cloned entity to a different name, then used this.HealthP = this.entity.findByPath(‘HealthP’); to find the bar thats only attaced to the CLONED entity so it only effects that cloned entitys health bar and not the Prefab, thank you all for your help, @Albertos helped me find it after a few hours. thanks

1 Like