I don’t know if the title is misleading
So I have a ammo system within my game but I need help making the UI actually work
local startNum = ammoData.currentMag
local currNum = startNum - 1
repeat
local UI = hud.Ammo.Main:FindFirstChild("Spare"..currNum)
if UI then
local sortOrder = startNum - currNum --My whole problem in this line
UI.LayoutOrder = sortOrder
end
currNum += 1
if currNum > #ammoData.spare then
currNum = 0
end
until currNum == startNum
-- Rest of the code is just resizing
What I want the end result to look like

The starting bar moves all the way to the end and the second bar becomes the first bar
What it looks like currently

Instead of moving the bar to the end, it just continues
P.S I can’t keep it like this because the player isn’t going to only have 5 magazines at a time, sometimes more, sometimes less