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

Why isn't my for loop teleport script working? For loop teleport not working..

Asked by 6 years ago

So I wrote a Server Script to teleport ALL players to a position when the intermission is up. I thought I could use a for loop to teleport them all but it doesn't seem to be working.

I'll explain with comments in the code block below..

local players = game.Players:GetChildren()
local roundRunning = false
local Intermission = true

if Intermission == true then
    local intermissionHint = Instance.new("Hint", workspace)
    for i = 30, 0, -1 do
        intermissionHint.Text = "Intermission: "..i
        wait(1)
        if i == 0 then
            wait(1)
            intermissionHint:Destroy()
            Intermission = false
            roundRunning = true
        end
    end
end

if roundRunning == true then
    for i,v in pairs(players) do  -- SO eh here. Yeah.
                                                    --[[ So as you can see here I tried to teleport all players in the server here. ]]--    
        v.Character.HumanoidRootPart.CFrame = CFrame.new(23.09, 11.473, 8.84)
    end
end

Anyone got any idea why this isn't working??

1 answer

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

Personally, I would use a pre-determined function in collaboration with your Intermission If Statement.

local players = game.Players:GetChildren()
local roundRunning = false
local Intermission = true

function teleportPlayers()
    for i,v in pairs(players) do
        HRP = v.Character.HumanoidRootPart
            HRP.CFrame = CFrame.new(23.09, 11.473, 8.84)
    end
end

if Intermission == true then
    local intermissionHint = Instance.new("Hint", workspace)
    for i = 30, 0, -1 do
        intermissionHint.Text = "Intermission: "..i
        wait(1)
        if i == 0 then
            wait(1)
            intermissionHint:Destroy()
            Intermission = false
            roundRunning = true
        teleportPlayers()
        end
    end
end


0
It's working now! Thanks, don't see much of a different, but it's working. Thanks! :D andyad13 74 — 6y
Ad

Answer this question