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

Why is GetPlayers() only detecting one player?

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
1 year ago

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.

Ad

Answer this question