How to make a UI start from the top to bottom

Please is someone goods with UIs? Im trying to make the bar go start from the top currently its starting from the bottom:

PROBLEM - Currently the bar starts from the bottom:

WHAT I WANT TO ACHIEVE - The bar starts from the top:

UI ELEMENTS:

local player = game.Players.LocalPlayer
local char = player.Character or player.ChildAdded:Wait()
local hum = char:WaitForChild("Humanoid")

function resizeCustomLoadingBar(sizeRatio, clipping, top)
	clipping.Size = UDim2.new(clipping.Size.X.Scale, clipping.Size.X.Offset, sizeRatio, clipping.Size.Y.Offset)
	top.Size = UDim2.new(top.Size.X.Scale, top.Size.X.Offset, (sizeRatio > 0 and 1 / sizeRatio) or 0, top.Size.Y.Offset)
end

while true do task.wait()
	local healthRatio = hum.Health / hum.MaxHealth
	resizeCustomLoadingBar(healthRatio, script.Parent.ImageLabel.Clipping, script.Parent.ImageLabel.Clipping.Top)
end
1 Like

Is the white part or the gray part the bar?

The white part is the bar and the grey part is the one that serves as the background for the bar

Which one are you trying to resize?

The white bar is the one I am trying to resize its also called “Top”

local player = game.Players.LocalPlayer
local char = player.Character or player.ChildAdded:Wait()
local hum = char:WaitForChild("Humanoid")

function resizeCustomLoadingBar(sizeRatio, clipping, top)
    -- Update the size and position of the clipping element
    clipping.Size = UDim2.new(clipping.Size.X.Scale, clipping.Size.X.Offset, sizeRatio, clipping.Size.Y.Offset)
    clipping.Position = UDim2.new(clipping.Position.X.Scale, clipping.Position.X.Offset, 1 - sizeRatio, clipping.Position.Y.Offset)
    
    -- Adjust the top overlay to match the clipping height
    top.Size = UDim2.new(top.Size.X.Scale, top.Size.X.Offset, (sizeRatio > 0 and 1 / sizeRatio) or 0, top.Size.Y.Offset)
end

while true do
    task.wait()
    local healthRatio = hum.Health / hum.MaxHealth
    resizeCustomLoadingBar(healthRatio, script.Parent.ImageLabel.Clipping, script.Parent.ImageLabel.Clipping.Top)
end

1 Like

Try changing the AnchorPoint of it.

This is what happened:

How can I change the achorPoint?

can you try this rq?

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

function resizeCustomLoadingBar(sizeRatio, clipping, top)
    clipping.Size = UDim2.new(clipping.Size.X.Scale, clipping.Size.X.Offset, sizeRatio, clipping.Size.Y.Offset)
    clipping.Position = UDim2.new(clipping.Position.X.Scale, clipping.Position.X.Offset, 1 - sizeRatio, clipping.Position.Y.Offset) -- Adjust position
    top.Size = UDim2.new(top.Size.X.Scale, top.Size.X.Offset, (sizeRatio > 0 and 1 / sizeRatio) or 0, top.Size.Y.Offset)
end

while true do 
    task.wait()
    local healthRatio = hum.Health / hum.MaxHealth
    resizeCustomLoadingBar(healthRatio, script.Parent.ImageLabel.Clipping, script.Parent.ImageLabel.Clipping.Top)
end

1 Like

GuiObject.AnchorPoint

I would suggest using this instead of manually offsetting it with code.

My health is 80 and its still similar to the 1st screenshot I have sent:

Change the anchor point of the white part to Vector2.yAxis

why don’t you just use a UIGradient?

1 Like