Achieve
I’m attempting to make this health bar script not error or break at all.
The Issue
I get an error of everytime I try to fix this script.
It tends to not retrieve the data of the health properly when it breaks.
Note
I did not make this script, as much as I wish I could say I made this… I didn’t and that’s why i’m bringing it here. It’s a free health bar that errors often.
The Script
function _G.round(n)
return n - math.floor(n) >= 0.5 and math.ceil(n) or n - math.floor(n) < 0.5 and math.floor(n)
end
wait(0.5)
local char = game.Players.LocalPlayer.Character
hum = char.Humanoid
Digit = script.Parent.Holder.HealthbarHolder.Digits
Round = (_G.round(hum.Health))
hum.Changed:connect(function()
script.Parent.Holder.HealthbarHolder.Healthbar.Size = UDim2.new(hum.Health/hum.MaxHealth,0,0.65,0)
Round = (_G.round(hum.Health))
Digit.Text = (Round.."%")
if hum.Health <= hum.MaxHealth*0.20 then
script.Parent.Holder.HealthbarHolder.Healthbar.BackgroundColor3 = Color3.new(255,0,0)
else
script.Parent.Holder.HealthbarHolder.Healthbar.BackgroundColor3 = Color3.new(0, 255, 0)
end
end)
Thank you to anyone who reads and attempts to help me solve this issue.