Help how do i create a button alphabetical order sorter system

I currently have too many buttons for a player to scroll through to find the right animals, so I want to create a sorter system that works like this: after going through a for loop to find the child buttons it’s going to orderly drop them alphabetically. child.Position = child.Position * UDim2.new(0, 0, startpos, 0)
2022-10-05

1 Like

You can use LayoutOrder and check each textbox’s text.

Example code:

local FrameHolder = script.Parent

local function SortFrames()
	local frames = {}
	
	for i, child in ipairs(FrameHolder:GetChildren()) do
		if child:IsA("Frame") then
			table.insert(frames, child)
		end
	end
	
	table.sort(frames, function(frame1, frame2)
		return frame1.TextLabel.Text:lower() < frame2.TextLabel.Text:lower()
	end)
	
	for i, sortedFrame in ipairs(frames) do
		sortedFrame.LayoutOrder = i
	end
end

SortFrames()

This sorting method works by comparing the string.byte values of each text.

1 Like

It looks like you’re manually setting the Position of your GuiObjects. Katrist’s approach of using LayoutOrder won’t work if you do it like this, only if you use UIListLayout to automatically position the objects. The same way of sorting the items will still work for your situation if you really want to make the list “manually” like that, just sort the items and set their Position in a for loop and use the item’s index to calculate the Y position