so, I don't have an error on this script, but rather I am seeking expansion on it - right now, it sorts a dictionary "kill table" by value, and after that is done, it writes to a "rank table" (called "placetable" here). what i want to happen before it writes to the rank table is it also sorts each kill numbers ascending by the least death down to the most before it goes downward to another variable. in other words, how a standard leaderboard in video games work. i have thought of a few ways on how this could be done without seeking help but they have all fallen flat.
note that the "death table" is also a dictionary but is not sorted in any specific way.
function getkeyssortedbyvalue(tbl, sortFunction)
local keys = {}
for key in pairs(tbl) do
table.insert(keys, key)
end
table.sort(keys, function(a, b)
return sortFunction(tbl[a], tbl[b])
end)
return keys
end
function updateleaderboardtables()
local place = 0
placetable = {}
local sortedkill = getkeyssortedbyvalue(killtable, function(a, b) return a > b end)
for _, key in ipairs(sortedkill) do
place = place + 1
placetable[key] = place
print(key, killtable[key])
end
end

1 comment
Dictionaries don't have an order so you cannot guarantee that there will be order with a dictionary.