Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

All players in game loop?

Asked by
kingdom5 5269 Trusted Snack Break Moderation Voter Community Moderator
4 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 3857 Trusted Badge of Merit Snack Break Moderation Voter Administrator Community Moderator Super Administrator
4 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 kingdom5 5269 — 4y
0
Good question though. If you need more help on this subject, PM me on ROBLOX and I'll gladly help. Shawnyg 3857 — 4y
0
I prefer :GetPlayers since it won't effect other children in Players, if any were to be placed. systematicaddict 290 — 4y
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 3857 — 4y
0
Use GetPlayers noob jk. kingdom5 5269 — 12d
Ad
Log in to vote
0
Answered by
Vividex 157
4 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