I am making a round based game where there are 2 leadersats, 1 that resets each round (Egg Points) and one that saves using data stores (Win Points).
LeaderboardGUI looks like this mid round:
[Player | Egg Points | Win Points]
[-------|------------|-----------]
[Joe36 | 90 | 5 ]
[ITxx1a | 74 | 1 ]
[User27 | 21 | 0 ]
[RBLxx | 20 | 1 ]
[PlayG | 18 | 0 ]
[sadboy | 3 | 0 ]
What I want is that at the end of the round I will call a function (from a module script) that finds the top 5 players and awards them "Win Points" in the following manner:
#1 = 10pt #2 = 5pt #3 = 3pt #4 = 1pt #5 = 1pt
I have looked up tutorials on youtube etc but the only things that were coming up was how to make 'global' leaderboards which is nothing to do with what I'm after.
I believe I need to put it in a table and sort it, but because the table is full of sub-tables I don't know how to order it since table.sort only works with number values and from lowest to highest, where I want it the highest to lowest
Here's the function I have written
module.FindTopPlayer = function()
local leaderstats = {}
for i,v in pairs(game.Players:GetChildren()) do
table.insert(leaderstats, {v.leaderstats:FindFirstChild("Egg Points").Value, v})
table.sort(leaderstats)
end
local handler = leaderstats[1]
handler[2].leaderstats:FindFirstChild("Win Points").Value = handler[2].leaderstats:FindFirstChild("Win Points").Value + 10
local handler = leaderstats[2]
handler[2].leaderstats:FindFirstChild("Win Points").Value = handler[2].leaderstats:FindFirstChild("Win Points").Value + 5
local handler = leaderstats[3]
handler[2].leaderstats:FindFirstChild("Win Points").Value = handler[2].leaderstats:FindFirstChild("Win Points").Value + 3
local handler = leaderstats[4]
handler[2].leaderstats:FindFirstChild("Win Points").Value = handler[2].leaderstats:FindFirstChild("Win Points").Value + 1
local handler = leaderstats[5]
handler[2].leaderstats:FindFirstChild("Win Points").Value = handler[2].leaderstats:FindFirstChild("Win Points").Value + 1
end
Any help would be very much appreciated. Thanks

1 comment
FYI the playernames, I just made up randomly