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

Players don't get teleported to the map for some reason?

Asked by 3 years ago
Edited 3 years ago

Hi, I'm new to programming and have been trying to make players in my game get teleported to the map. However, for some reason it just doesn't work. No errors, but the players just stay in the lobby forever. I've included the main code that's supposed to teleport the players. Thanks to anyone that helps!

wait(10)

    local plrs = {}

    for i, player in pairs(game.Players:GetPlayers()) do
        if player then
            table.insert(plrs,player) -- Add each player into plrs table
        end
    end

    wait(2)

local AvailableMaps = MapsFolder:GetChildren()

local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]

Status.Value = ChosenMap.Name.." Chosen"

local ClonedMap = ChosenMap:Clone()

    ClonedMap.Parent = workspace

    -- Teleport players to map

    local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")

    if not SpawnPoints then
        print ("Spawnpoints not found!")
    end

    local AvailableSpawnPoints = SpawnPoints:GetChildren()

for i, player in pairs(plrs) do
    if player then
        character = player.Character
        if character then
                -- Teleport them

                character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
                table.remove(AvailableSpawnPoints,1)

Answer this question