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

This part of my code isn't teleporting the players?

Asked by 6 years ago
Edited 6 years ago

I can't figure out why this part in my script isn't working when it tries to teleport all players to the map. What it does is insert all the players into a table then I use a for loop to get all the players in the table. Then, whenever I assign each player a spawn to be teleported to, it just doesn't teleport them and gives no error.

    --insert players into table
    for _, player in pairs(game.Players:GetPlayers()) do
        table.insert(_G.gamePlayers, player)
    end

    --teleport players
    for _, player in pairs(_G.gamePlayers) do
        local spawns = randomMap:FindFirstChild("Spawns"):GetChildren()

        if #spawns > 0 then
            local head = player.Character:FindFirstChild("Head")
            local allSpawns = spawns[math.random(1, #spawns)]
            local randomSpawn = table.remove(spawns, math.random(#spawns))

            if head and randomSpawn then
                head.CFrame = CFrame.new(randomSpawn.Position + Vector3.new(0, 2, 0))
            end
        end
    end
0
can you show me the entire script. LifeInDevelopment 364 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Instead of lines 4-12 just use table.remove on the global table to remove the player that died.

-- Im on mobile so excuse my lack of indentation

for i, v in pairs (_G.gamePlayers) do
if v == player then
table.remove(_G.gamePlayers, i)
end
end
0
replace lines 4-12 on the second script with ^ LifeInDevelopment 364 — 6y
0
oh and the reason what script wasnt working was because you didnt add a capital p to gamePlayers on line 12 LifeInDevelopment 364 — 6y
Ad

Answer this question