Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Damage meter/leaderboard problem, Help!?

Asked by
Nymint 85
10 years ago

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. ):

0
Are there any errors? GoldenPhysics 474 — 10y
0
Nope, I know how to manage everything else, but I'd like to know how to get all player's TotalDamage Value and sort them by top 5, from top to bottom in a gui. Nymint 85 — 10y
0
It's sad to see how all questions get answered and this one is the only that remains unanswered.. ): Nymint 85 — 10y

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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
0
This seems to be the solution, thanks, Azarth, +1. Nymint 85 — 10y
Ad

Answer this question