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})

8 comments

0

Is there anything in the output?

0

Nothing

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.

0

So what should it be?

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.

0

Mind putting that in an answer for me?

0

You've asked this question before.

0

I dont believe I have.