How to fix this health bar issue?

Hello all!

For my game, my goal is to make a working and functional Health Bar GUI.
However, something in the code doesn’t make the sizing right…
What should happen:
image
What actually happens:
image
When the health changes:
image

Could anyone help? The code is in a LocalScript, which is in a frame.

Code:

wait(0.2)
while true do
	local hp = game.Players.LocalPlayer.Character.Humanoid.Health/100
	script.Parent:TweenSize((UDim2.new(hp,0,1,0)),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
	wait(0.2)
end

I would suggest adding another frame and parenting the bar to the frame. Sorta like this:
image

1 Like

Just make your health bar parent a frame.

Example GUI:

HealthBar.rbxm (4.9 KB)


Example Place:

HealthBarGui.rbxl (31.7 KB)


Thank you both for your solutions! Im dumb xd

Hi My Name Is Kia! I Have Experience In This Problem!

Try This Code :

-- All This Code Must Same With The Parent - Child Name
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)


local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local healthbar = script.Parent:WaitForChild("HealthBar") -- The Name Must Same


game:GetService("RunService").RenderStepped:Connect(function()
	local humanoid = char:FindFirstChild("Humanoid")
	healthbar.GreenFrame.Size = UDim2.new(humanoid.Health/humanoid.MaxHealth,0,1,0)
	healthbar.HealthStatus.Text = math.floor(humanoid.Health).."/"..humanoid.MaxHealth
end)

here’s the Parent - Child :

That’s All My Explain I Hope This Is Help You From The Problem!