So i have a dictionary that holds the player and the amount of dmg they did. How do I sort this dictionary and return a table of highest damager to lowest?
You can’t sort this table, because this table does not have a numerical order. Sorting is putting things in order, but if your keys are strings, you can’t have an order.
Clone keys into a new array, then sort that array by the value associated with that key in the Humanoid’s dictionary.
local Dictionary = {
[Humanoid] = {
["KreatorKols"] = 3,
["GoldKols"] = 12,
["Locks"] = 7,
}
}
local Output = {}
for i, _ in pairs(Dictionary[Humanoid]) do
table.insert(Output, i)
end
table.sort(Output, function(a, b)
return Dictionary[Humanoid][a] > Dictionary[Humanoid][b]
end)
print(Output)