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

The player doesn't get teleported in the first loop, what am I doing wrong?

Asked by 4 years ago
Edited 4 years ago
local t = 11
local storage = workspace.Storage
local round = storage.Round
local label = storage.String

round.Value = false

while true do
    --Variables
    local player = game.Players:GetChildren()
    local team = game.Teams
    local spectator = team.Spectators:GetChildren()
    local runner = team.Runners:GetChildren()


    t = 10
    while t >= 0 do
        label.Value = "Intermission... "..t
        wait(1)
        t = t - 1
    end

    label.Value = "Teleporting Players"
    wait(1)
    for i, v in ipairs(player) do
        local num = math.random(1, 35)
        if v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
            v.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Map.Spawn[num].Position)
        end
    end
    wait(1)

    t = 3
    while t <= 0 do
        label.Value = "Starting in... "..t
        wait(1)
        t = t - 1
    end
end

This is my script. When I start the game, in the first while loop I don't get teleported but when while loops again I get teleported, I tried printing print(player[1]) and in the first loop it gave me nil and after that it got normal, I'm confused this was working in a different script on another game.

The script is named "main" and is in ServerScriptService, I've tried putting it in Workspace but that doesn't change anything.

Also, I just got started with Lua, that's why I may be using unconventional methods ;-;

Edit: Fixed the HumanoidRootPart Typo, still isn't working.

Edit-2: Okay it's working now, I put the GetChildren Variables under the intermission block, so that the game gets the players after they have loaded in. Thanks though ^-^

Answer this question