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

Teleport Players from a table?

Asked by 5 years ago

Ummm not much to say other than i want to teleport all Players in the global table called _G.Players but if i insert it there

for _, player in pairs (_G.Players) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')
.
.
.

it will give me a Error that Character is a nil value

but if I do it like this

for _, player in pairs (game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')

Everything works without errors but i dont want that. because it would teleport all Players that are currently in the game. I just want to teleport the Players inside the _G.Players Table. Any solution for that? Here is my whole teleport script if you need it

    --Teleport tributs
    local spawns = map:WaitForChild("Spawns"):GetChildren()
for _, player in pairs (game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')
        local allspawns = math.random(1, #spawns)
        local randomspawn = spawns[allspawns]
        if randomspawn and torso then
            table.remove(spawns, allspawns)
            torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
        end
    end
end
0
Don't use _G, use whatever script is creating _G.players to teleport them instead and do player.Character or player.CharacterAdded:Wait() followed up with your HumanoidRootPart line Vulkarin 581 — 5y
0
This doesnt help me much. Paintertable 171 — 5y
0
line 3 -> char = player.Character or player.CharacterAdded:Wait()....line 4 -> char:WaitForChild("HumanoidRootPart") Vulkarin 581 — 5y
0
Such an edit runs the risk of teleporting people mid-round though, maybe it would be better to just check if the character is spawned in already? Vulkarin 581 — 5y

Answer this question