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

Why does my SurfaceGUI leaderboard not work?

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

✓ Accepted answer

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

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