Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats wrong with my healthbar?

Asked by
neoG457 315 Moderation Voter
8 years ago
wait(.5)
game:GetService("StarterGui"):SetCoreGuiEnabled("Health", false)
 plr = game.Players.LocalPlayer 
 chr = plr.Character
 hum = chr.Humanoid
 sp = script.Parent
 bar = sp.Bar
 hbar = bar.Health

while wait(.001) do
    hbar.Size = UDim2.new(hum.Health/hum.MaxHealth - 0.368, 0, 0, 35)
    if hum.Health<=20 then
        hbar.BackgroundColor3=Color3.new(255/255, 0, 0)
    else hbar.BackgroundColor3=Color3.new(0, 255/255, 0)
    end
end

hubar = bar.Hunger

This local script controls the health bar, This is the layout:

layout

It works well but the length of the healthbar isnt equal to my health. Like whenever my health is 10 the healthbar falls into negative numbers and looks like this:

Health Bar problem

How do I stop this from happening? (the original length of the health bar is {0, 700},{0, 35})

0
Is there anything in the output? ChipioIndustries 454 — 8y
0
Nothing neoG457 315 — 8y
0
It's because of the scale value, you're subtracting .368 from the scale which when your health reaches 36.8 will start the scale being a negative value, thus providing you with your current result. M39a9am3R 3210 — 8y
0
So what should it be? neoG457 315 — 8y
View all comments (4 more)
0
I would recommend that if using scale values for health bars, that they be between 0 and 1, which the Health/MaxHealth will provide. M39a9am3R 3210 — 8y
0
Mind putting that in an answer for me? neoG457 315 — 8y
0
You've asked this question before. GullibleChapV2 155 — 8y
0
I dont believe I have. neoG457 315 — 8y

Answer this question