Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Damage meter/leaderboard problem, Help!?

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

3 comments

0

Are there any errors?

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.

0

It's sad to see how all questions get answered and this one is the only that remains unanswered.. ):

1 answer

✓ Accepted answer

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

1 comment

0

This seems to be the solution, thanks, Azarth, +1.

This discussion is preserved as it was. New answers, comments, and votes are closed.