I want to achieve a map system that loads a map simply, and cleans it up afterward. I’m using parts right now for testing.
The issue is that when ever the map loading function is called, it in cloned, and removed immediately.
I looked on the creator hub, nothing, I looked for Youtube videos, not specific enough, and I tried ChatGPT (Never should’ve done that, and yes I know StOp UsINg cHAtGpt FoR STufF iT’S So BAd!!!1!)
Here is module loader I’m using, and the module scripts that are doing the generation and round stuff. (And yes I know the code is really sloppy I’m kind of a beginner scripter)
Server Script Module Loader
--[[Server Module Loader]]
local scriptsFolder = script.Parent.Scripts
local serverModules = {}
local function LoadServerModules()
for _, module in pairs(scriptsFolder:GetChildren()) do
if module:IsA("ModuleScript") and not serverModules[module.Name] then
local success, result = pcall(function()
local requiredModule = require(module)
serverModules[module.Name] = requiredModule
if requiredModule.Init then
requiredModule.Init()
else
return
end
end)
if not success then
warn(result)
end
end
end
return serverModules
end
LoadServerModules()
local globalLoader = require(game.ReplicatedStorage:WaitForChild("Global"):WaitForChild("Loader"))
local globalModules = globalLoader.LoadGlobalModules()
Maps Manager Module
--[[Services]]
local RepStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
--[[Main System]]
local MapsManager = {}
local maps = {}
--[[Helper Modules and Networking]]
local MapLoadedUIEvent = RepStorage:WaitForChild("Networking"):WaitForChild("Events"):WaitForChild("RoundSystem"):WaitForChild("MapLoadedEvent")
--[[Main System Cont.]]
function MapsManager.Init()
local MapsFolder = ServerStorage:WaitForChild("Maps")
for _, map in pairs(MapsFolder:GetChildren()) do
table.insert(maps, map)
end
end
function MapsManager.SendUIUpdates(UIString)
MapLoadedUIEvent:FireAllClients(UIString)
task.wait(1.5)
end
function MapsManager.LoadRandomMap()
local chosenMap = maps[math.random(1, #maps)]
if not chosenMap then
return
end
local newMap = chosenMap:Clone()
newMap.Name = "CurrentMap"
newMap.Parent = workspace
MapsManager.SendUIUpdates("Map Chosen: " .. chosenMap.Name)
end
function MapsManager.RemoveCurrentMap()
task.wait(3)
end
return MapsManager
Round Manager Module
--[[Services]]
local RepStorage = game:GetService("ReplicatedStorage")
--[[Main System]]
local RoundManager = {
INTER_TIME = script:GetAttribute("INTER_TIME"),
ROUND_TIME = script:GetAttribute("ROUND_TIME"),
PhaseType = script:GetAttribute("PhaseType")
}
--[[Helper Modules and Networking]]
local MapsManager = require(script.Parent:WaitForChild("MapsManager"))
--Add a player teleport module later
local SendTimeEvent = RepStorage:WaitForChild("Networking"):WaitForChild("Events"):WaitForChild("RoundSystem"):WaitForChild("SendTimeEvent")
--[[Main System Cont.]]
function RoundManager.Init()
task.spawn(function()
while true do
RoundManager.StartRound()
end
end)
end
function RoundManager.StartRound()
if RoundManager.PhaseType == "Intermission" then
for phaseTime = RoundManager.INTER_TIME, 0, -1 do
SendTimeEvent:FireAllClients(phaseTime, RoundManager.PhaseType)
task.wait(1)
end
local success, result = pcall(function()
MapsManager.SendUIUpdates("Map Loading...")
MapsManager.LoadRandomMap()
MapsManager.SendUIUpdates("Map Loaded!")
MapsManager.SendUIUpdates("Round Starting...")
end)
if success then
RoundManager.PhaseType = "Round"
else
warn(result)
end
elseif RoundManager.PhaseType == "Round" then
for phaseTime = RoundManager.ROUND_TIME, 0, -1 do
SendTimeEvent:FireAllClients(phaseTime, RoundManager.PhaseType)
task.wait(1)
end
local success, result = pcall(function()
MapsManager.RemoveCurrentMap()
MapsManager.SendUIUpdates("Intermission")
end)
if success then
RoundManager.PhaseType = "Intermission"
else
warn(result)
end
end
end
return RoundManager
The module loader is a server script and the modules are both server sided. I hope this helps. Thank you for your time.