Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

All players in game loop?

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

✓ Accepted answer

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.

5 comments

0

The reason whay i was asking if it would work in SeverScriptService is becouse this script is not sent to the client

0

Good question though. If you need more help on this subject, PM me on ROBLOX and I'll gladly help.

0

I prefer :GetPlayers since it won't effect other children in Players, if any were to be placed.

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.

0

Use GetPlayers noob jk.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.