I currently have a localscript to update a playerlist I’ve made in a GUI, I’ve added multiple print functions to see what was not working and it doesn’t even print the first line which comes right after of game.Players.PlayerAdded. No output response.
Script:
local sample = script.Parent.DisplayArea.Players.Player
game.Players.PlayerAdded:connect(function(player)
print('player added') -- This doesn't even print
local newgui = sample:Clone()
print('gui cloned')
newgui.Visible = true
newgui.Parent = script.Parent.DisplayArea.Players:WaitForChild('ScrollingFrame')
print('gui moved')
newgui.Name = player.Name
newgui.Row.Disabled = false
end)
game.Players.PlayerRemoving:connect(function(player)
for i,v in pairs( script.Parent.DisplayArea.Players:WaitForChild('ScrollingFrame'):GetChildren()) do
if v.Name == player.Name then
v:Destroy()
end
end
end)
If it’s a LocalScript, players are already going to be in-game by the time it connects to PlayerAdded. Try looping through existing players and calling the same function.
That’s weird, I was watching a tutorial where the person used PlayerAdded, I guess I just misinterpreted, will try to do what you guys said in order to fix this.
That’s because the player probably joins before the event connection is created. That’s why you have to rewrite that a little bit.
local sample = script.Parent.DisplayArea.Players.Player
local addPlr = function(player)
print('player added') -- This doesn't even print
local newgui = sample:Clone()
print('gui cloned')
newgui.Visible = true
newgui.Parent = script.Parent.DisplayArea.Players:WaitForChild('ScrollingFrame')
print('gui moved')
newgui.Name = player.Name
newgui.Row.Disabled = false
end)
game.Players.PlayerAdded:Connect(addPlr)
for _,plr in pairs(game:GetService("Players"):GetPlayers()) do
addPlr(plr)
end
game.Players.PlayerRemoving:Connect(function(player)
for i,v in pairs( script.Parent.DisplayArea.Players:WaitForChild('ScrollingFrame'):GetChildren()) do
if v.Name == player.Name then
v:Destroy()
end
end
end)
However that solves only one problem, the second one is that you should be doing that in a server script so it needs another fix. (edit thanks to @posatta; I didn’t notice that you are creating a local player list and I thought that it is some globally visible list)