✓ Accepted answer
Online, the Character and the Humanoid probably won't exist when the script runs, so we should definitely wait for those.
repeat wait() until player.Character
local h = player.Character:WaitForChild("Humanoid")
Anyways, your main problem is that the Changed event won't be firing when you respawn. This is because the Humanoid is already at full health by the time it's connected to the event, so no change is detected. This can easily be fixed in a single line:
local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character
local h = player.Character:WaitForChild("Humanoid")
script.Parent.Text = math.floor(h.Health)
h.HealthChanged:connect(function()
script.Parent.Text = math.floor(h.Health)
end)
2 comments
Um, dude, I tested this out again, the same thing happened.
Explain, por favor. It worked when I tested it. Although on second though we should use HealthChanged instead of Changed, just for efficiency.