table.sort doesn’t return your table, it sorts the table that is given.
Instead, do:
print("BEFORE", Scores)
-- Sort the PlayerScores into order
local sortedtable = table.sort(Scores, function(a, b)
return a.Points > b.Points
end)
print("AFTER", sortedtable)
It looks like “Scores” is a dictionary (with the keys being each player’s UserId). Dictionaries are unordered collections, table.sort only works on arrays.
function GetKeySet(dictionary)
local array = {}
for key in pairs(dictionary) do
table.insert(array, key)
end
return array
end
local ScoresKeySet = GetKeySet(Scores)
table.sort(ScoresKeySet, function(aKey, bKey)
local a = Scores[aKey]
local b = Scores[bKey]
return a.Points > b.Points
end)
for i, key in ipairs(ScoresKeySet) do
print(i, Scores[key])
end