It's a script a leader board, which works by collecting all the players to a table, then generating a Frame for each of them, one by one and it always restarts when someone leaves/joins. The problem is that I can't the Player using the table I have. It just won't find it.
(Non local-script)
local playercount = 0
local playerlist = {}
local curr_player
function Regenerate()
playerlist = {}
for _, player in pairs(game.Players:GetPlayers()) do
table.insert(playerlist, player)
end
playercount = #playerlist
for i=1, playercount+1 do
curr_player = game.Players:FindFirstChild(playerlist[i])
local persFrame = Instance.new("Frame", script.Parent.Main)
--Design..
local persPoint = Instance.new("TextBox", persFrame)
persPoint.Name = "Points"
--Desing...
print(playerlist[i]) --This shows the player's name correct
persPoint.Text = curr_player.Name --This is where I get the error
end
end
function onPlayerAdded(player)
Regenerate()
end
game.Players.PlayerRemoving:connect(function(player)
Regenerate()
end)
game.Players.PlayerAdded:connect(onPlayerAdded)
I get an error that says it can't get "curr_player" Name, because it's a nil. I'm sure it must be a tiny error, but i'm really looking forward to find it out. Thanks for the advice.

1 comment
Why do you need to create a separate for loop to add a GUI to them? Why not just do it for the first for loop?