Health Bar scaling issue

Hi!

So I made a Health Bar but the problem is that when I add myself more MaxHealth in the Humanoid, the bar just goes off the limit of the frame.

Let me show you the screenshots.


When I don’t add MaxHealth

image

When I add MaxHealth

image

Bar Script

wait()

game.StarterGui:SetCoreGuiEnabled("Health",true)
game.StarterGui:SetCoreGuiEnabled("Health",false)


local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")


Humanoid.HealthChanged:Connect(function()
script.Parent.Overlay:TweenSize(UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0),"Out","Quad",.25)
end)

Any help is appreciated!

1 Like

I think an easy fix would be to not add the max health to the bar, but instead, just change the number and have the HP drain proportionately to the max hp

1 Like

What do you mean? I don’t really understand.

Try this out

script.Parent.Overlay:TweenSize(UDim2.new((1/Humanoid.MaxHealth)*Humanoid.Health,0,1,0),"Out","Quad",.25)
1 Like

Nope, doesn’t work at all.

Also what’s the point of doing HP * 1 ?

My bad meant to do divided instead of multiply, 1 is supposed to be the max length it can reach

1 Like

Oh okay. I’ll change it myself then.

So the bar just completely dissapeared-

Did you use this formula?

(1/Humanoid.MaxHealth)*Humanoid.Health
1 Like

Yeah. But it just dissapears when HP changes.

Haven’t made a regular healthbar for a while so I mixed some stuff up, this should work:

1-(health/maxHealth)
1 Like

Doesn’t work.

It grows when I lose HP not when I earn them.

health/maxhealth and multiply this by your bars length.

3 Likes

This worked perfectly.
Tysm! : D

1 Like