https://gyazo.com/4cbf374bf42c8990918fb3010430ca5e
It's just a simple healthbar script. Btw I'm still new to scripting.
local player = game.Players.LocalPlayer local health = script.Parent local character = player.Character or player.Character:Wait() local hum = character:WaitForChild("Humanoid") while wait() do local percent = hum.Health / hum.MaxHealth health.Size = UDim2.fromScale(percent - 0.06, 0.574) --hmmmmm health.Text = math.floor(player.Character.Humanoid.Health) end
Maybe use math.clamp() when setting percent's value? If the health is less than 0 then you will get a negative number. math.clamp(percent, 0, 1) would keep the value between 0 and 1. To clarify, your new script would look like this:
local player = game.Players.LocalPlayer local health = script.Parent local character = player.Character or player.Character:Wait() local hum = character:WaitForChild("Humanoid") while wait() do local percent = hum.Health / hum.MaxHealth percent = math.clamp(percent, 0, 1) health.Size = UDim2.fromScale(percent - 0.06, 0.574) --hmmmmm health.Text = math.floor(player.Character.Humanoid.Health) end
I'm not too familiar with using math.clamp but I am pretty sure that this will fix your problem. Let me know if it doesn't.