Hey everyone!
So, I’m currently developing a game in which, every 120 seconds, a new map generates. And I want to add a timer that starts counting every time a new map is generated. But when I try to destroy the map and create a new one, it doesn’t delete it, and the timer stops with the map still there.
Any ideas on what I am doing wrong?
Here is the main game script:
math.randomseed(tick())
local map1 = game.ReplicatedStorage.Maps.Map1
local map2 = game.ReplicatedStorage.Maps.Map2
local map3 = game.ReplicatedStorage.Maps.Map3
local allinall = game.ReplicatedStorage.Maps.AllInAll
local map1show = game.StarterGui.CurrentMap1
local map2show = game.StarterGui.CurrentMap2
local map3show = game.StarterGui.CurrentMap3
local map4show = game.StarterGui.CurrentMap4
local onetwentytimer = game.StarterGui.OneTwentyTimer
local onetwentytimer2 = game.StarterGui.OneTwentyTimer2
local onetwentytimer3 = game.StarterGui.OneTwentyTimer3
local oneeightytimer = game.StarterGui.OneEightyTimer
function clonemap1 ()
local map1clone = map1:Clone()
map1clone.Parent = game.Workspace
map1show.Enabled = true
onetwentytimer.Enabled = true
while onetwentytimer.Enabled == true do
task.wait(1)
if onetwentytimer.Enabled == false then
map1clone.Destroy()
map1show.Enabled = false
onetwentytimer.Enabled = false
break
end
end
end
function clonemap2 ()
local map2clone = map2:Clone()
map2clone.Parent = game.Workspace
map2show.Enabled = true
onetwentytimer2.Enabled = true
while onetwentytimer2.Enabled == true do
task.wait(1)
if onetwentytimer2.Enabled == false then
map2clone.Destroy()
map2show.Enabled = false
onetwentytimer2.Enabled = false
break
end
end
end
function clonemap3 ()
local map3clone = map3:Clone()
map3clone.Parent = game.Workspace
map3show.Enabled = true
onetwentytimer3.Enabled = true
while onetwentytimer3.Enabled == true do
task.wait(1)
if onetwentytimer3.Enabled == false then
map3clone.Destroy()
map3show.Enabled = false
onetwentytimer3.Enabled = false
break
end
end
end
function allinallclone ()
local allclone = allinall:Clone()
allclone.Parent = game.Workspace
map4show.Enabled = true
oneeightytimer.Enabled = true
while oneeightytimer.Enabled == true do
task.wait(1)
if oneeightytimer.Enabled == false then
allclone.Destroy()
map4show.Enabled = false
oneeightytimer.Enabled = false
break
end
end
end
while true do
local randomnum = math.random(1,4)
if randomnum == 1 then
print(randomnum)
clonemap1()
end
if randomnum == 2 then
print(randomnum)
clonemap2()
end
if randomnum == 3 then
print(randomnum)
clonemap3()
end
if randomnum == 4 then
print(randomnum)
allinallclone()
end
end
If you need any other script, don’t hesitate to reply asking me for it.
Thank You!