Dictionary automatically sorting itself

im trying to make a script that sorts a dictionaries values from smallest to greatest but whenever i print it it looks fine but if i put it into another dictionary it doesn’t look the same.

local dictionary = {
	["Player6"] = 10,
	["Player1"] = 69,
	["Player4"] = 560,
	["Player2"] = 50,
	["Player5"] = 629,
	["Player3"] = 45
}

local temptable = {}
local tempdictionary = {}

for i, v in dictionary do
	table.insert(temptable,v)
end
table.sort(temptable)

for index, value in temptable do
	for i, v in pairs(workspace.Map:FindFirstChildWhichIsA('Folder').playersInGame:GetChildren()) do
		if dictionary[v.Name] then
			if value == dictionary[v.Name] then
				print(v.Name.." "..value)
				tempdictionary[v.Name] = value
			end
		end
	end
end
--dictionary = tempdictionary
--tempdictionary = {}
temptable = {}
print(tempdictionary)

Dictionaries, as you can tell, automatically sort based on the name of the items

There isnt exactly a work around for this, as this is just how they work, but if you get creative with tables, for instance, instead of using v.Name as the key, you could just use Value instead. Thus it would sort based on the value.

Thats basically one of the best ways that I think you could go about it.
Hope this helps :D

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