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

Why don't the names re-position correctly in my custom leader-board?

Asked by 7 years ago

I'm working on a custom leaderboard. Here's a snip of some of the code where it's supposed to sort the playername position based on their score.

01for h,q in pairs(script.Parent.LeaderBoard.Holder.players:GetChildren()) do
02    game.ReplicatedStorage:WaitForChild(q.Name)
03    q.Kills.Text =  game.ReplicatedStorage:FindFirstChild(q.Name).currentrounddata.killsthisround.Value
04    q.Deaths.Text =  game.ReplicatedStorage:FindFirstChild(q.Name).currentrounddata.deathsthisround.Value
05            table.insert(scores, q.Kills.text)
06        table.sort(scores, function(a,b) return a > b end)
07print('starting player sort')
08for g = 1, #players do
09for i,v in pairs(scores) do
10    print(i,v)
11    if v == q.Kills.Text then print(q.Name)
12        if i <= #players then
13    local y = .50
14    local pos = i * .06 + y
15    label.Parent = script.Parent.LeaderBoard.Holder.players
View all 23 lines...

Below, it prints the output correctly. Ranking the scores through the table.

1            table.insert(scores, q.Kills.text)
2        table.sort(scores, function(a,b) return a > b end)
3print('starting player sort')
4for g = 1, #players do
5for i,v in pairs(scores) do
6    print(i,v)

But, in the block below it only prints one name(q.Name) and it only re-positions one name, causing an overlap.

1if v == q.Kills.Text then print(q.Name)
2    if i <= #players then
3local y = .50
4local pos = i * .06 + y
5label.Parent = script.Parent.LeaderBoard.Holder.players
6label.Position = UDim2.new(.5, -300, pos, -100)

Any help would be appreciated!

Answer this question