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

How do I fix this error?

Asked by 8 years ago

I made a round system about a week ago and after it loads the map it's supposed to teleport all the players in the lobby to the map, but it's giving me this error saying 'chosenMap is not a valid member of Workspace'. I'm not sure how I could fix this error so I was hoping if anyone could help me out, thanks!

'Map Code'

function mapSelection()
    mapList = game.ReplicatedStorage.CS_ReplicatedStorage.CS_Maps.Maps:GetChildren()
    randomMap = math.random(1, #mapList)
    playerNotification("Choosing the map!")
    wait(4)
    mapChosen = mapList[randomMap]
    playerNotification("The map is: " ..mapChosen.Name)
    mapClone = mapChosen:Clone()
    mapClone.Parent = game.Workspace
    chosenMap = mapClone
    chosenMap.Parent = game.Workspace
end

Round Script:

chosenMap = mapClone

function playerNotification(changeText)
    for _,v in pairs (game.Players:GetChildren()) do
        local gameInterface = v.PlayerGui:FindFirstChild("GameInterface")
        if gameInterface then
            gameInterface.Frame.TextLabel.Text = changeText
        end
    end
end

function waitForPlayers()
    while game.Players.NumPlayers < 2 do
        playerNotification("You need 1 more player to start the round!")
        wait(0)
    end
end

function intermissionTimer()
    if game.Players.NumPlayers >= 2 then
        for countDown = 10, 0, -1 do
            playerNotification("Intermission: " ..countDown)
            wait(1)
        end
    end
end

function displayGamemode()

end

function mapSelection()
    mapList = game.ReplicatedStorage.CS_ReplicatedStorage.CS_Maps.Maps:GetChildren()
    randomMap = math.random(1, #mapList)
    playerNotification("Choosing the map!")
    wait(4)
    mapChosen = mapList[randomMap]
    playerNotification("The map is: " ..mapChosen.Name)
    mapClone = mapChosen:Clone()
    mapClone.Parent = game.Workspace
    chosenMap = mapClone
    chosenMap.Parent = game.Workspace
end

function teleportAllPlayers()
    local mapSpawn = CFrame.new(workspace.chosenMap.Spawns:GetChilren().Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = mapSpawn + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 1
    end
end

function startTimer()
    for countDown = 3, 0, -1 do
        playerNotification("Game begins in: " ..countDown)
        wait(1)
    end
end

function roundTimer()
    for countDown = 20, 0, -1 do
        playerNotification("Time left: " ..countDown)
        wait(1)
    end
end

function playersCurrentlyPlaying()
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.Playing.Value == 1 then return true end
    end
    return false
end

function roundEnded()
    playerNotification("The round has ended!")
end

function teleportAlivePlayers()
    local mapSpawn = CFrame.new(workspace.CS_Workspace.CS_Lobby.Lobby.Spawns:GetChildren().Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = mapSpawn + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 0
    end
end

function mapDestroy()
    if chosenMap.Parent == game.Workspace then
        chosenMap:Destroy()
    end
end

function showResults()

end

game:GetService('Players').PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        Character:FindFirstChild("Humanoid").Died:connect(function()
            Player.Playing.Value = 0
        end)
    end)

    local Playing = Instance.new("IntValue", Player)
    Playing.Value = 0
    Playing.Name = "Playing"
end)

while true do
    waitForPlayers()
    wait(0)
    intermissionTimer()
    wait(0)
    displayGamemode()
    wait(5)
    mapSelection()
    wait(5)
    teleportAllPlayers()
    wait(0)
    startTimer()
    wait(0)
    roundTimer()
    wait(0)
    playersCurrentlyPlaying()
    wait(0)
    roundEnded()
    wait(0)
    teleportAlivePlayers()
    wait(0)
    mapDestroy()
    wait(0)
    showResults()
end
1
Which line is the error on? TheDeadlyPanther 2460 — 8y
0
Nearing from 41 to 46. Vestralix 15 — 8y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

chosenMap is a variable, not an object inside workspace. You already have chosenMap so you don't need to access it from workspace.

Replace workspace.chosenMap with chosenMap

Ad

Answer this question