I’m making a simple map rotation system for my game that I do plan to replace with a better system eventually, but currently, this script deletes the map and clears the terrain on the first attempt. However, it keeps the map in the Workspace every subsequent time the script runs. I put a demonstration below.
Here is my script:
local map = workspace:GetChildren()
local mapfd = game:GetService("ServerStorage"):WaitForChild("Maps")
math.random(1,3)
repeat
for _, object in ipairs(map) do
if object:GetAttribute("IsMap") then
wait(3)
object:Destroy()
workspace.Terrain:Clear()
end
end
function pickmap(newmap)
if newmap == 1 then
print("picking")
wait(3)
mapfd.Map1:Clone().Parent = workspace
elseif newmap == 2 then
print("picking")
wait(3)
mapfd.Map2:Clone().Parent = workspace
elseif newmap == 3 then
print("picking")
wait(3)
mapfd.Map3:Clone().Parent = workspace
end
end
print(pickmap(math.random(1,3)))
until 2+2==5
wait()