How to order Table from Most Damage to Least

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?

Dictionary Example :

local Dictionary = {
	[Humanoid] = {
		["KreatorKols"] = 3,
		["GoldKols"] = 12,
		["Locks"] = 7,
	}
}

Desired Output :
local Output = {"GoldKols","Locks","KreatorKols"}

This should work I think.

Dictionary = table.sort(Dictionary, function(a, b)
   return a > b
end)

print(Dictionary)
local Dictionary = {
    [workspace.Test.Humanoid] = {
        ["KreatorKols"] = 23,
        ["SSS"] = 2,
        ["23232"] = 21
    }
}


Dictionary = table.sort(Dictionary, function(a, b)
   return a > b
end)

print(Dictionary)

This printed nil because the Dictionary isnt a table

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)
3 Likes