So I have this loop
player = game:GetService("Players")
for i, v in pairs(player:GetPlayers()) do print(v.." has joined the game") end
But when i play the game nothings prints out what could be the error?
So I have this loop
player = game:GetService("Players")
for i, v in pairs(player:GetPlayers()) do print(v.." has joined the game") end
But when i play the game nothings prints out what could be the error?
it is working, but because the server runs before any player is on the game, the loop recives a empty table, try adding a wait() before the loop, so your player can load and connect to the server
Yeah of course stupid me, thank you
I'm not sure how to explain thats wrong, but here is a better solution to it (place this in a normal script in workspace or serverscriptservice)
game:GetService("Players").PlayerAdded:Connect(function(player)
print(player.Name.." has joined the game.")
end)
and if you want to print when somebody leaves
game:GetService("Players").PlayerRemoving:Connect(function(player)
print(player.Name.." has left the game.")
end)
"Yeah, thank you but how do i add all the players in the game into a in pairs loop?"
for i, v in pairs(game:GetService("Players"):GetChildren()) do
print("Player name: "..v.Name)
end
Yeah, thank you but how do i add all the players in the game into a in pairs loop?
So i just tested, it works when i do it inside of a LocalScript but not a Script, but does that matter?
It shouldn't really matter, but they should both work in either a LocalScript and a Script, maybe the Script is running just after you join, making it not detect you entering.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I have updated my post to answer your question :)