Sort table (medium before hard)

Hey guys, I’ve got into an issue with my script.
can you help me to sort the table so medium will be before hard?
image

local mylevels = {}
for i, v in pairs(levelsvalues:GetChildren()) do
	if v:IsA("Folder") then
		table.insert(mylevels,v)
	end
end
	

table.sort(mylevels, function(p2, p3)
	return p2.Name < p3.Name;
end);
table.sort(mylevels, function(p4, p5)
	if p4:GetAttribute("level") == p5:GetAttribute("level") then
		return p4.Name < p5.Name;
	end;
	return p4:GetAttribute("level") < p5:GetAttribute("level");
end);

You compare the name of the two difficulties. If you compare the name, it will return the table sorted alphabetically (first is E, then H and then M). You can assign a number to these difficulties, lets say easy is 1, medium is 2 and hard is 3, and then compare that number to check which should come first.

These look like buttons, if they are being constrained via UIListLayout or UIGridLayout, you can simply just change the LayoutOrder property on the button instances.

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