Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I sort objects that has an ID (1, 2, 3 etc) in order by their ID number?

How would I sort a folder that consists of hats, hairs, etc. that has an IntValue to represent which order they should go in inside a table? I'm not sure if I asked this correctly, had to re-type this 4 times. Here's a picture example:

http://prntscr.com/jhgu62

Not sure how to go about this, my brain isn't working entirely well as of now. Could anyone lead me in the right direction?

1 comment

0

why not make the hat number and the id same? (hat1, id =1)

1 answer

You can use table.sort to do this, by passing in a comparator function:

-- First create a table of your objects
local objects = workspace.Folder:GetChildren()

-- Now use table.sort to get the order that you want
table.sort(objects, function(obj1, obj2)
	return obj1.ID.Value < obj2.ID.Value
end)

This code assumes your folder is called Folder, and is in the workspace, and the IntValue of each object is called ID. You will need to change this to match how you have things set up.

This discussion is preserved as it was. New answers, comments, and votes are closed.