I need help with my HP Bar

I want to achieve a working HP bar that goes down when the player receives damage.

I have tried watching youtube tutorials, but no matter what, my HP bar doesn’t scale correctly.

I’ve tried for 1 hour and I simply can’t get it to work.

My code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

humanoid.HealthChanged:Connect(function(Damage)
	script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0, 1, 0)
end)

This is the bar:

image

The bar’s size and position:
image

The bar after receiving 1 tick of damage:
image

You need to make your size using scale instead of offset.m
Scale is the first (Position: ScaleX, OffsetX, ScaleY, OffsetY)

1 Like
UDim2.new(0, (humanoid.Health / humanoid.MaxHealth) * 387, 0, 21)

You need to scale it like this. Also, I would recommend putting the healthbar into a frame that has the exact same size and position, and making the healthbar’s size 1,0,1,0, and then you can scale it like UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0), it would be a lot easier

2 Likes