Health bar not working after respawning

I am working on a HUD that contains health, stamina and xp. Everything works seemingly well until I either die or reset. The health is working like it should be, but after it goes down to 0, it doesn’t go back to 100 once the player respawns. I am aware this can be fixed by turning off ResetOnSpawn on the ScreenGui, but the only problem with this is that it affects the experience bar. What can I do?

All help appreciated!

1 Like

Maybe you have to separate the GUIs. I had to re-read the realize you mentioned you can’t use ResetOnSpawn.

You could have the health bar and the experience bar as two different frames. Then have the health bar set as ResetOnSpawn and leave the experience bar as it is.

This is basically just a coding thing.

(The easiest way (non coding) is to split the experience bar and the health bar.)


It’s easier to explain this if you give some code, but basically you just need to manage your player’s characters’ humanoids. The simplest way to do this is

  • Create an UpdateHealth function, which updates the health based on the Player.Character and possibly its Humanoid (remember to handle the case where the character doesn’t exist :+1:)
  • Get the player with Players.LocalPlayer
  • Connect to Player.CharacterAdded
  • Every time a character is added, update the UI bar, and connect to the new character’s humanoid’s Died and HealthChanged events. Call UpdateHealth when either of these events happen (using RBXScriptSignal:Connection).

And that’s it! Sorry if the explanation is a bit hard to follow, it’s easier if I have some code to reference.

1 Like

Please provide script(s). We can’t solve and issue if we don’t see the code.

1 Like

Maybe you could move the exp bar in another screengui with ResetOnSpawn on true and keep the Health in the screengui with ResetOnSpawn on false?

When the player dies and respawns, their previous character model gets removes from the workspace along with their humanoid. So, the HealthChanged connection also disconnects, which is why it doesn’t display the full health when they respawn.

To fix this, you need to create the connection every time the player’s character is added to the workspace. Something like

local player = game.Players.LocalPlayer -- the local player

player.CharacterAdded:Connect(function(character) -- executes when the player's character is added to the workspace
    local humanoid = character.Humanoid        

    humanoid.HealthChanged:Connect(function() -- executes every time the humanoid's health changes
        -- your code
    end)
end)

would do the trick since the connection gets renewed each time their character spawns in.