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

Alternating maps using CTF Template?

Asked by
saucyP 7
7 years ago

I already made a couple maps, and I put them into a Folder called Maps, which is in ReplicatedStorage. Apparently the script that handles the map is in game.ServerScriptService.MainGameScript.GameManager.MapManager. Here's the code of that script:

local MapManager = {}

-- Local Variables
local MapSave = Instance.new('Folder', game.ServerStorage)
MapSave.Name = 'MapSave'

-- Initialization

local MapPurgeProof = game.Workspace:FindFirstChild('MapPurgeProof')
if not MapPurgeProof then
    MapPurgeProof = Instance.new('Folder', game.Workspace)
    MapPurgeProof.Name = 'MapPurgeProof'
end

-- Functions

function MapManager:SaveMap()
    for _, child in ipairs(game.Workspace:GetChildren()) do
        if not child:IsA('Camera') and not child:IsA('Terrain') and not child:IsA('Folder') then
            local copy = child:Clone()
            if copy then
                copy.Parent = MapSave
            end 
        end
    end
end

function MapManager:ClearMap()
    for _, child in ipairs(game.Workspace:GetChildren()) do
        if not child:IsA('Camera') and not child:IsA('Terrain') and not child:IsA('Folder') then
            child:Destroy()
        end
    end
end

function MapManager:LoadMap()
    spawn(function()
        for _, child in ipairs(MapSave:GetChildren()) do
            local copy = child:Clone()
            copy.Parent = game.Workspace
        end
    end)
end

return MapManager

I don't really see how the function SaveMap is that useful, since I'm going to be alternating maps. I just don't know what I should do, or if the answer is super obvious and I'm just not getting it.

1 answer

Log in to vote
0
Answered by
saucyP 7
7 years ago

Here's what I've tried so far;

local MapManager = {}

-- Local Variables
local MapSave = Instance.new('Folder', game.ServerStorage)
MapSave.Name = 'MapSave'
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local randomMap = math.random(1, #Maps)

-- Initialization

local MapPurgeProof = game.Workspace:FindFirstChild('MapPurgeProof')
if not MapPurgeProof then
    MapPurgeProof = Instance.new('Folder', game.Workspace)
    MapPurgeProof.Name = 'MapPurgeProof'
end

-- Functions

function MapManager:SaveMap()
    for _, child in ipairs(game.Workspace:GetChildren()) do
        if not child:IsA('Camera') and not child:IsA('Terrain') and not child:IsA('Folder') then
            local copy = child:Clone()
            if copy then
                copy.Parent = MapSave
            end 
        end
    end
end

function MapManager:ClearMap()
    for _, child in ipairs(game.Workspace:GetChildren()) do
        if not child:IsA('Camera') and not child:IsA('Terrain') and not child:IsA('Folder') then
            child:Destroy()
        end
    end
    game.Workspace.MapsInGame:ClearAllChildren() --tried to delete any map that's in the folder
end

function MapManager:LoadMap()
    --[[spawn(function()
        for _, child in ipairs(MapSave:GetChildren()) do
            local copy = child:Clone()
            copy.Parent = game.Workspace
        end
    end)--]]
    local currentMap = game.ReplicatedStorage.Maps:GetChildren(math.random(1, #Maps)) --tried to get a random map from the folder
    local insertMap = currentMap:Clone() --tried to clone the map
    insertMap.Parent = game.Workspace.MapsInGame --tried to put the map into the workspace (in a folder)
end

return MapManager

However, this time the map isn't even being inserted into the workspace. No errors.

Ad

Answer this question