So I made a health display using math.floor. The only problem is, every time I reset, it still shows 0 when I respawn. Why?
local player = game:GetService("Players").LocalPlayer local h = player.Character.Humanoid h.Changed:connect(function() script.Parent.Text = math.floor(h.Health) end)
If you could help, I'd appreciate that.
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) --Now the text will be set to the Health once, no matter what, when the code first runs. h.HealthChanged:connect(function()--And every time it changes. script.Parent.Text = math.floor(h.Health) end)