Custom health bar when health is lost moves to center instead of left

Hello. I am trying to make my custom healthbar health subtract to the left side. The problem is it goes to the middle instead.

image image

I tried editing some variables for the equation to subtract the health. No success.

the script i used is here:

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


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

That’s weird, I don’t see any wrong with your code. Try switching the Humanoid/MaxHealth on the Y-axis scale of the GUI?

i wasnt exactly sure what you meant by “switching the Humanoid/MaxHealth on the Y-axis scale of the GUI” but i tried this:

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


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

the healthbar just got bigger instead

I meant this.

script.Parent.Size = UDim2.new(1,0,Health/humanoid.MaxHealth,0

after the script.Parent.Size code just reset the position to the left

This seems like it could be an issue with the object’s AnchorPoint. Try setting it to 0, 0 in the Studio explorer.

1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")


humanoid.HealthChanged:Connect(function(Health)
	script.Parent.Size = UDim2.fromScale(math.clamp(Health/humanoid.MaxHealth, 0,1), 1)
end)

Help me with health gui with stackable bars (aka health bar with life) - Help and Feedback / Scripting Support - DevForum | Roblox

it just stops the bar from changing at all