Hello there developers. I am trying to achieve a custom healthbar gui. The main problem is as the title says that it does not update after a player dies or resets. I have currently tried to rescript the healthbar twice with the same result. By documenting myself I understood that this issue might be created by the fact that once a player resets or dies they get a new character/humanoid.
Code:
local function updateHealthBar()
local health = humanoid.Health / humanoid.MaxHealth
local tweenInfo = TweenInfo.new (0.5)
local tween = TS:Create(
healthbar,
tweenInfo,
{Size = UDim2.fromScale(health, 1)}
)
tween:Play()
end
updateHealthBar()
humanoid:GetPropertyChangedSignal('Health'):Connect(updateHealthBar)
You’re right it may be an issue that the health isn’t “changed” and firing the event when a new character arrives. Perhaps try using Player.CharacterAdded to detect they’ve respawned, and update their health accordingly?
I’m afraid it is enabled and I have noticed that instead of player.CharacterAdded I typed Players.ChildAdded but that still didn’t solve the issue.
Remove the PlayerAdded function, it should be working properly. If ResetOnSpawn is enabled on the gui and you reset the player, it’s just like as if you just joined the game.