Vertical health bar not Working

Yo! i made a hearth bar that is vertical, it was work but for some reason it sized upward and not downward. I write a code that change the position of the bar to the bottom of the canvas group so when sized it goes downward, when i tested it, it still going upward idk what it did wrong

anyway here is the script

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

local gui = script.Parent.Parent
local frame = gui:FindFirstChild("Frame")

local healthFrame = frame:FindFirstChild("HealthFrame")

local bar = healthFrame:FindFirstChild("Bar")

local soundFolder = workspace:FindFirstChild("Sound")
local heartbeat = soundFolder and soundFolder:FindFirstChild("Heartbeat")
local breathing = soundFolder and soundFolder:FindFirstChild("Heavy Breathing")

local function updateHealthDisplay(health)
	local ScaleY = bar.Size.Y.Scale
	bar.Size = UDim2.new(1, 0, math.clamp(health / 100, 0, 1), 0)
	bar.Position = UDim2.new(0, 0, 1 - ScaleY, 0)
end

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    updateHealthDisplay(humanoid.Health)
end)

updateHealthDisplay(humanoid.Health)

and also this

Thanks =D

1 Like

Did you mean to put ScaleY after the size is changed?

bar.Size = UDim2.new(1, 0, math.clamp(health / 100, 0, 1), 0)
local ScaleY = bar.Size.Y.Scale
bar.Position = UDim2.new(0, 0, 1 - ScaleY, 0)

There’s an event called HealthChanged that passes the player’s health as an argument. You may want to use that instead.

humanoid.HealthChanged:Connect(updateHealthDisplay)

It actually work =D, thanks for the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.