Vertical Health Frame subtracting upwards instead of downwards

Hello everyone, I’ve made some modifications to a Health Bar UI to turn it vertical, however the frame is subtracting upwards instead of downwards, which is what I’m trying to achieve.

image

I have tried different UDim2.new values, changing the frame’s anchor points and SizeConstraint, looked online for possible solutions, but no luck with my current (or rather lack thereof) knowledge of scripting. (To be honest I have been using ChatGPT to try and write scripts, which has been both a blessing and a curse, but that’s another topic).

A few details on the hierarchy and properties:

In StarterGUI:

Hierarchy

image

“Bar” Properties

Properties

The LocalScript itself (Credit to AdvancedDrone for creating it):

LocalScript
local StarterGui = game:GetService('StarterGui')
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

local Player = game.Players.LocalPlayer
local Character

repeat Character = Player.Character wait() until Character ~= nil

function GetTools(Model)
	local Num = 0
	for _, v in pairs(Model:GetChildren()) do
		if v:IsA("Tool") or v:IsA("HopperBin") then
			Num = Num + 1
		end
	end
	return Num
end

function Transformar(R, G, B)
	return Color3.new(R/255, G/255, B/255)
end

function Actualizar()
	local Tools = 0
	Tools = Tools + GetTools(Player.Backpack) + GetTools(Player.Character)
	if Tools == 0 then
		script.Parent:WaitForChild("HPBackground").Position = UDim2.new(0, 10,1, -52)
	else
		script.Parent:WaitForChild("HPBackground").Position = UDim2.new(0, 10,1, -52)
	end
end

delay(0, function()
    Player.Character.Humanoid.Changed:connect(function()
        if Player.Character.Humanoid.Health == math.huge then
            -- God mode: Set the health bar to full height
            script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(51, 255, 51)
            script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").Size = UDim2.new(1, 0, 1, 0)
            script.Parent:WaitForChild("HPBackground"):WaitForChild("DamageBar").Size = UDim2.new(1, 0, 1, 0)
        else
            -- Calculate health percentage
            local Calculo = Player.Character:WaitForChild("Humanoid").Health / Player.Character:WaitForChild("Humanoid").MaxHealth
            -- Update the health bar's height and animate it
            script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").Size = UDim2.new(1, 0, Calculo, 0)
            script.Parent:WaitForChild("HPBackground"):WaitForChild("DamageBar"):TweenSize(UDim2.new(1, 0, Calculo, 0), "In", "Quad", 0.25, true)
            -- Set the health bar's background color
            local Var = Player.Character:WaitForChild("Humanoid").MaxHealth / 4
            if Player.Character:WaitForChild("Humanoid").Health <= Var then
                script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 51, 51)
            elseif Player.Character:WaitForChild("Humanoid").Health <= Var * 2 then
                script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 170, 0)
            elseif Player.Character:WaitForChild("Humanoid").Health <= Var * 3 then
                script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 255, 51)
            else
                script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(51, 255, 51)
            end
        end
    end)
end)

Any suggestions would help immensely.

3 Likes

You should be able to achieve this without altering your script. Set the frames Position that represents the remaining health [Bar] to {0, 0},{1, 0} and the AnchorPoint to 0, 1.

3 Likes

Simple problems require simple solutions. Thank you sir!

2 Likes

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