Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

All players in game loop?

Asked by 10 years ago

How can I find and loop through every player currently in the game? I have enabled filtering so I need to change a lot of my scripts.

And should this script be in "ServerScriptService"?

2 answers

Log in to vote
4
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

This could be in SeverScriptService or Workspace. If by "looping through every player", you mean using the GetChildren method, then I recommend using a for loop. The other for loop is pairs. Exmaple:

for i,v in pairs(game.Players:GetChildren()) do
v:Kick()
end

Sorry for the spacing. I'm not in studio.

The above script would kick each player in the game.

0
The reason whay i was asking if it would work in SeverScriptService is becouse this script is not sent to the client User#5423 17 — 10y
0
Good question though. If you need more help on this subject, PM me on ROBLOX and I'll gladly help. Shawnyg 4330 — 10y
0
I prefer :GetPlayers since it won't effect other children in Players, if any were to be placed. systematicaddict 295 — 10y
0
That would work as well. Normally, people don't play any other objects to become a descendant of Players. There's really no need to. Shawnyg 4330 — 10y
0
Use GetPlayers noob jk. User#5423 17 — 5y
Ad
Log in to vote
0
Answered by
Vividex 162
10 years ago

You would use a for loop and the GetChildren() method.

    for i,v in pairs(game.Players:GetChildren()) do --States the for loop, which gets all the children's names and prints them in v
    print(v) --Prints the players names
    wait() --So the for loop doesn't crash
end --Ends the for loop

VOTE +1 IF THIS HELPED :)

Answer this question