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

How do I get all players in a game?

How do I get all players in a game? (I need to teleport all players to a part, for a round-based game)

1 comment

0

game.Players:GetChildren()

1 answer

✓ Accepted answer

Hey IfIWasntSoSwag,

This website is not one used for requests. You are supposed to provide us with some code and then we help you out with the issues you might be facing with that block of code. You have to at the least try to make the thing you need help with otherwise, it's just non-productive and you don't learn anything from it. However, this is how I would get all the players and teleport them to a part named "Part" in workspace.

local players = game:GetService("Players"):GetChildren();
local part = workspace:WaitForChild("Part");

for _, player in next, players do
	local char = player.Character or player.CharacterAdded:wait();
	local torso = char:WaitForChild("Torso") or char:WaitForChild("UpperTorso");
	torso.CFrame = part.CFrame;
end

Above, I used for each iteration, variables, :WaitForChild() method, CharacterAdded:wait(), and CFrames. The links for those are below.

Here is the for each iteration. Roblox Lua calls it a 'Generic For Loop'

Here is the variables wiki page.

Here is the :WaitForChild() method wiki page.

Here is the CharacterAdded:wait() wiki page.

Here is the CFrame wiki page.

#Thanks for reading this answer and I hope you have a good day/night.

~~ KingLoneCat

4 comments

0

Accept this answer so people don't have to see this question.

0

Actually, this is a concepts question. Which is allowed. All you simply have to do is explain GetPlayers and how a for loop works.

0

@M39a9am3R oh, mb.

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