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

How come the script isn't teleporting everyone?

Asked by 5 years ago

Hello everybody. So I want to teleport players to a brick. But the script below only teleports 1 player in the server. And not everyone. How do I fix it? Thanks.

--spawns is the part i want people to teleport to
spawns = game.Workspace.spawns

for i,v in pairs(game.Players:GetPlayers()) do
        local name = v.name
            local checkplayer = check:FindFirstChild("Humanoid")
            if checkplayer then
                v.Character.HumanoidRootPart.CFrame = spawns.CFrame
0
Correction: Line 6 is local checkplayer = v.Character:FindFirstChild("Humanoid") A_nsonn 4 — 5y

1 answer

Log in to vote
0
Answered by
Pojoto 329 Moderation Voter
5 years ago

When the game starts, this script is running instantly, and probably most of the player's characters haven't loaded in yet. This means checkplayer would be nil and the teleportation wouldn't take place.

You can add a wait in the beginning but I suggest you change

local checkplayer = check:FindFirstChild("Humanoid")

to

local checkplayer = check:WaitForChild("Humanoid")

This would hold the script until the child is found, which is the Humanoid. This would mean it won't skip over certain players who haven't fully loaded in yet, it would wait for them.

Ad

Answer this question