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.
for h,q in pairs(script.Parent.LeaderBoard.Holder.players:GetChildren()) do game.ReplicatedStorage:WaitForChild(q.Name) q.Kills.Text = game.ReplicatedStorage:FindFirstChild(q.Name).currentrounddata.killsthisround.Value q.Deaths.Text = game.ReplicatedStorage:FindFirstChild(q.Name).currentrounddata.deathsthisround.Value table.insert(scores, q.Kills.text) table.sort(scores, function(a,b) return a > b end) print('starting player sort') for g = 1, #players do for i,v in pairs(scores) do print(i,v) if v == q.Kills.Text then print(q.Name) if i <= #players then local y = .50 local pos = i * .06 + y label.Parent = script.Parent.LeaderBoard.Holder.players label.Position = UDim2.new(.5, -300, pos, -100) else print(i.."Is over number of players! Error!") end end end end end
Below, it prints the output correctly. Ranking the scores through the table.
table.insert(scores, q.Kills.text) table.sort(scores, function(a,b) return a > b end) print('starting player sort') for g = 1, #players do for i,v in pairs(scores) do 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.
if v == q.Kills.Text then print(q.Name) if i <= #players then local y = .50 local pos = i * .06 + y label.Parent = script.Parent.LeaderBoard.Holder.players label.Position = UDim2.new(.5, -300, pos, -100)
Any help would be appreciated!