Automatic Gui Order System

Hello scripters, I’m trying to make a system that adds buttons in a certain order but I can’t find a way to make that work here is an example

As you can see the buttons appear in a random order, does anyone know how I could do so that they are ordered as I want?

This is the code I use to order them

for _,d in pairs(SongFolder[ModFrameSchemeClone.Name].Songs[s.Name].Difficulties:GetChildren()) do
	local DifficultieFrameSchemeClone = DifficultiesFrameScheme:Clone()

	DifficultieFrameSchemeClone.Name = d.Name
	DifficultieFrameSchemeClone.Visible = true
	DifficultieFrameSchemeClone.Parent = DifficultiesFrameScheme.Parent
	DifficultieFrameSchemeClone.Position = UDim2.new(DifficultiesFrameScheme.Position.X.Scale, 0, OldDifficultiesPositionY, 0)

	DifficultieFrameSchemeClone.TextButton.Text = d.Name

	OldDifficultiesPositionY = OldDifficultiesPositionY + 0.11
end
1 Like
for _,d in ipairs(SongFolder[ModFrameSchemeClone.Name].Songs[s.Name].Difficulties:GetChildren()) do
	local DifficultieFrameSchemeClone = DifficultiesFrameScheme:Clone()

	DifficultieFrameSchemeClone.Name = d.Name
	DifficultieFrameSchemeClone.Visible = true
	DifficultieFrameSchemeClone.Parent = DifficultiesFrameScheme.Parent
	DifficultieFrameSchemeClone.Position = UDim2.new(DifficultiesFrameScheme.Position.X.Scale, 0, OldDifficultiesPositionY, 0)

	DifficultieFrameSchemeClone.TextButton.Text = d.Name

	OldDifficultiesPositionY = OldDifficultiesPositionY + 0.11
end

ipairs goes through the given argument in order. :grin:

1 Like

I also tried to use it but in this case it doesn’t work
image

local table2loopthru = SongFolder[ModFrameSchemeClone.Name].Songs[s.Name].Difficulties:GetChildren()
table.sort(table2loopthru,function(a,b)
return a.Name > b.Name
end)
for _,d in pairs() do
	local DifficultieFrameSchemeClone = DifficultiesFrameScheme:Clone()

	DifficultieFrameSchemeClone.Name = d.Name
	DifficultieFrameSchemeClone.Visible = true
	DifficultieFrameSchemeClone.Parent = DifficultiesFrameScheme.Parent
	DifficultieFrameSchemeClone.Position = UDim2.new(DifficultiesFrameScheme.Position.X.Scale, 0, OldDifficultiesPositionY, 0)

	DifficultieFrameSchemeClone.TextButton.Text = d.Name

	OldDifficultiesPositionY = OldDifficultiesPositionY + 0.11
end
1 Like

Just use UIListLayout. It automatically will set it out in a nice, customisable list without you needing to do all that + 0.12 stuff. It also has support for LayoutOrder which you can use to order them.

2 Likes

Wow, I didn’t know, thanks, I’ll do some research on that.

1 Like