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
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