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

Why does my SurfaceGUI leaderboard not work?

Asked by 10 years ago

Hi guys, I've tried to make a script where a SurfaceGUI would state the name and score of the player who had the highest score in a table in first place and the lowest score in a table in second place. I tried to also make it so it sorts the player by their PlayerNum value in the player (which is created when the player is added) if their score is equal to both numbers in the table (AKA: If both values in the table are the same.) However, when I test the script in start server/player mode, the players don't appear on the leaderboard with their scores when my mini-game starts, but no output is shown. How could I fix this? Any help is appreciated, thank you!

local scr = {};

while game.Workspace.TargetStarted.Value == true do
wait();
for i,v in pairs(game.Players:GetPlayers()) do
if v.PlayerNum.Value == 1 or v.PlayerNum.Value == 2 then
table.insert(scr, v.Score.Value);
wait();
table.sort(scr, function (x, y) return x > y; end);
wait();
if v.Score.Value == scr[1] then
script.Parent.First.PName.Text = v.Name;
script.Parent.First.PScore.Text = v.Score.Value;
elseif v.Score.Value == scr[2] then
script.Parent.Second.PName.Text = v.Name;
script.Parent.Second.PScore.Text = v.Score.Value;
elseif v.Score.Value == scr[1] and v.Score.Value == scr[2] then
if v.PlayerNum.Value == 1 then
script.Parent.First.PName.Text = v.Name;
script.Parent.First.PScore.Text = v.Score.Value;
elseif v.PlayerNum.Value == 2 then
script.Parent.Second.PName.Text = v.Name;
script.Parent.Second.PScore.Text = v.Score.Value;
end;
end;
end;
end;
wait();
scr = {};
end;

1 answer

Log in to vote
3
Answered by 10 years ago

I believe your 'for' at line 5 should end at line 8

Ad

Answer this question