How can I sort a dictionary from smallest to greatest?

Hey! Let’s say I have a dictionary like this:

	local dictionary = {
		Part1 = "2", 
		Part2 = "7",
		Part3 = "18",
		Part4  = "1",
		Part5 = "4"
	}

How could I make a script that sorts it into:

	local dictionary = {
		Part4 = "1",
		Part1 = "2",
		Part5 = "4",
		Part2 = "7",
		Part3 = "18",
	}

The dictionary part of a table has no notion of order. Use an an array instead.

Okay, if I were to insert all the values inside of the array, how could I sort it?

You can use this concept here.

Placing it all in an array then putting it back in a Dictionary sorted.

Edit: Also found this online

1 Like

LOL! Hi, uhi_o. Thanks, it worked.

1 Like