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

Why is GetPlayers() only detecting one player?

The code I have is supposed to teleport every single player to one location. No matter what I do, it only picks up the first player that joined the game. I've been at this for hours, looked at several youtube tutorials as well.

This is a snippet of the code:

		for _, plr in pairs(game.Players:GetChildren()) do

			local char = plr.Character

			local xOffset = math.random(-10,10)
			local zOffset = math.random(-10, 10)
		
			plr.Team = game.Teams.Playing

			char.HumanoidRootPart.CFrame = Base.CFrame

			wait()
			beginningEvents()
		end

If you might know what the problem is, I would appreciate any help.

1 answer

✓ Accepted answer

There's nothing wrong at first glance with the code. It depends on what beginningEvents() does, since it is likely infinitely yielding which is why you only see it affecting one player. Also, do use Players:GetPlayers() instead of Players:GetChildren(). If you comment out line 13 and it sets everyone's team properly, then you know that the beginningEvents function is the issue.

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