I want to sort a dictionary into the order of total score. Quick example would be:
local Scores = {
["Player1"] = 5,
["Player2"] = 2,
["Player3"] = 19,
["Player4"] = 8,
}
function Sort(tbl)
local SortedTable = table.sort(tbl, function(a, b)
return a > b
end)
return SortedTable
end
print(Sort(Table))
print returns nil however. Basically, all the players scores would be assigned to their player, and I want the return table to ideally look as so
local Scores = {
["Player1"] = {
Rank = 3,
Tags = 5,
},
["Player1"] = {
Rank = 4,
Tags = 2,
},
["Player3"] = {
Rank = 1,
Tags = 19,
},
["Player4"] = {
Rank = 2,
Tags = 8,
},
}
-- How I do it
PlayerStats[Creator.Value] = {
Rank = Sort(PlayerStats),
Tags = 1
}