I'm making a Damage meter Gui, In order to make it, I need to know how to get the top 5 best damage dealers first then sort them in order so it's top 1, top 2, top 3, top 4,and top 5 and the gui should update every second, setting the top 5 damage player leaderboard from top to bottom.
Now, this is my epic failed attempt:
while wait(1) do for i,v in ipairs(Game:GetService("Players"):GetPlayers()) do local Dps=v:WaitForChild("TotalDamage") local DpsGui=v:WaitForChild("HealthGui"):WaitForChild("DamageFrame") print(math.max(Dps.Value,i)) end end
Could anyone explain me how to get the top 5 best damagers after getting each player's Stored NumberValue?
PD: I postes this 5 days ago, but I still can't be able to do this... somebody help, please. ):
http://stackoverflow.com/questions/2038418/associatively-sorting-a-table-by-value-in-lua
6th answer
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 items = { azarth = 5, minish = 2, clockwork = 10, telamon = 4, } local sortedKeys = getKeysSortedByValue(items, function(a, b) return a < b end) for i,v in pairs(sortedKeys) do print(v,items[v]) end