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

Map clones, deletes from lighting, and then breaks the game, how do I fix this?

Asked by 7 years ago

Okay so I've already asked a bunch of questions concerning this one script but there always ends up being an error. In this script, the map clones, but then deletes itself from lighting, not allowing you to teleport to it again.. How do I fix it so it will just continuously run and not delete the map from lighting? (Also I would like to thank BlueTaslem for helping me clean and fix this script up! Also keep in mind that I am just beginning to understand scripting so I'm not sure how to fix this..) Thanks for stopping by! Hope you can help! Here is the script:

local Map1 = game.Lighting.Map1
local Map2 = game.Lighting.Map2
local Map3 = game.Lighting.Map3
local Map4 = game.Lighting.Map4
local Map5 = game.Lighting.Map5

local Maps = {
    game.Lighting.Map1,
    game.Lighting.Map2,
    game.Lighting.Map3,
    game.Lighting.Map4,
    game.Lighting.Map5,
}

LOBBY = Vector3.new(1.915, 915.46, -26.68)

math.randomseed(tick(7))

while true do
    wait(5)
    local msg = Instance.new("Message")
    msg.Parent = nil
    msg.Parent = game.Workspace
    msg.Text = "Welcome to Zombie Survival! Choosing a map!"
    wait(3)
    msg:Destroy()

    local chosenMap = math.random(1,5)
    local map = Maps[chosenMap]
    local msg = Instance.new("Message", workspace)

    map:Clone(). Parent = game.workspace

    msg.Text = "Loading map please wait."
    wait(0.5)
    msg.Text = "Loading map please wait.."
    wait(0.5)
    msg.Text = "Loading map please wait..."
    wait(0.5)
    msg.Text = "Loading map please wait."
    wait(0.5)
    msg.Text = "Loading map please wait.."
    wait(0.5)
    msg.Text = "Loading map please wait..."
    wait(1)
    msg.Text = "Map loaded! Teleporting players..."
    wait(1)
    msg:Destroy()
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character then
            player.Character:MoveTo(map.Spawnpos.Position + Vector3.new(0, 5, 0))
wait(10)
        end
    end

    local message = Instance.new("Message", workspace)
    message.Text = "Game end... Intermission!"
    map:remove()
    wait(1)
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character then
            player.Character:MoveTo(LOBBY)
        end
    end
    message:Destroy()
map:Destroy()
end


0
any errors? iamnoamesa 674 — 7y
0
Use ServerStorage. It removes a bit of lag. SH_Helper 61 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

What you're doing here is deciding on a map, then cloning that map onto workspace, but then your problem is that you delete the ORIGINAL copy of the map (Which is in workspace)-- Fixing this is really simple.

local Map1 = game.Lighting.Map1
local Map2 = game.Lighting.Map2
local Map3 = game.Lighting.Map3
local Map4 = game.Lighting.Map4
local Map5 = game.Lighting.Map5

local Maps = {
    game.Lighting.Map1,
    game.Lighting.Map2,
    game.Lighting.Map3,
    game.Lighting.Map4,
    game.Lighting.Map5,
}

LOBBY = Vector3.new(1.915, 915.46, -26.68)

math.randomseed(tick(7))

while true do
    wait(5)
    local msg = Instance.new("Message")
    msg.Parent = nil
    msg.Parent = game.Workspace
    msg.Text = "Welcome to Zombie Survival! Choosing a map!"
    wait(3)
    msg:Destroy()

    local chosenMap = math.random(1,5)
    local map = Maps[chosenMap]
    local msg = Instance.new("Message", workspace)

   local ClonedMap = map:Clone() -- This right here makes a variable "ClonedMap" that is the clone to map
ClonedMap.Parent = game.worspace -- This here takes the clone and puts it under workspace

    msg.Text = "Loading map please wait."
    wait(0.5)
    msg.Text = "Loading map please wait.."
    wait(0.5)
    msg.Text = "Loading map please wait..."
    wait(0.5)
    msg.Text = "Loading map please wait."
    wait(0.5)
    msg.Text = "Loading map please wait.."
    wait(0.5)
    msg.Text = "Loading map please wait..."
    wait(1)
    msg.Text = "Map loaded! Teleporting players..."
    wait(1)
    msg:Destroy()
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character then
            player.Character:MoveTo(map.Spawnpos.Position + Vector3.new(0, 5, 0))
wait(10)
        end
    end

    local message = Instance.new("Message", workspace)
    message.Text = "Game end... Intermission!"
    ClonedMap:Destroy() -- I believe that remove is deprecated 
    wait(1)
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character then
            player.Character:MoveTo(LOBBY)
        end
    end
    message:Destroy()
map:Destroy()
end

There may be other issues, but this is the answer to your question. This should now delete the cloned map.

Ad

Answer this question