local PlayersAndPointsSorted = table.sort(PlayersAndPoints,
function (a,b)
return a[2] > b[2]
end)
for i,v in pairs(PlayersAndPointsSorted) do
print(v[1].." - "..v[2])
end
table.sort doesn’t return a new table, instead it performs the sorting operation to the existing table, for example:
local PlayersAndPoints = {
{"Player1", 20},
{"Player2", 35},
{"Player3", 15},
}
function sortTable(a, b)
return a[2] < b[2]
end
table.sort(PlayersAndPoints, sortTable)
for i,v in pairs(PlayersAndPoints) do
print(v[1].." - "..v[2])
end