I'm making a core defense game and I'm having problems. I want the loop to return to the beggining when the core is destroyed and I also want the round timer to stop, I've looked but cant find the solution to any.
RoundManager ServerScriptService ServerScript
local status = game.ReplicatedStorage.Status
local players = script.Players
local maps = game.ServerStorage.Maps:GetChildren()
local Spectating = game.Teams["Lobby/Spectating"]
local DTeam = game.Teams.Defenders
local RTeam = game.Teams.Raiders
local MorphRoomD = game.Workspace.MorphRoomD
local MorphRoomR = game.Workspace.MorphRoomR
local playersneeded = 1
local roundlength = 500
local intermissionlength = 30
local function checkplayers()
if players.Value >= playersneeded then
return true
else
return false
end
end
local function IntermissionTimer()
for i = intermissionlength, 0, -1 do
wait(1)
status.Value = "Intermission: "..i.." seconds left!"
end
end
local function RoundTimer()
for i = roundlength, 0, -1 do
wait(1)
status.Value = "Round In Progress: "..i.." seconds left!"
end
end
local function Map()
local randomchosenmap = maps[math.random(1,#maps)]
status.Value = "Map Chosen!"
wait(1)
status.Value = "The Chosen map will be "..randomchosenmap.Name.."!"
mapclone = randomchosenmap:Clone()
mapclone.Parent = workspace
core = mapclone.Core
local morphRoomSpawnsD = MorphRoomD.Spawns:GetChildren()
local morphRoomSpawnsR = MorphRoomR.Spawns:GetChildren()
for i,player in pairs(game.Players:GetPlayers()) do
if player.Team == DTeam then
local char = player.Character or player.CharacterAdded:Wait()
local RandomMorphRoomSpawnD = morphRoomSpawnsD[math.random(1,#morphRoomSpawnsD)]
char.HumanoidRootPart.CFrame = RandomMorphRoomSpawnD.CFrame
elseif player.Team == RTeam then
local char = player.Character or player.CharacterAdded:Wait()
local RandomMorphRoomSpawnR = morphRoomSpawnsR[math.random(1,#morphRoomSpawnsR)]
char.HumanoidRootPart.CFrame = RandomMorphRoomSpawnR.CFrame
end
end
end
local function destroyMap()
mapclone:Destroy()
end
local function reloadAllPlayers()
for i,player in pairs(game.Players:GetPlayers()) do
player:LoadCharacter()
end
end
while wait() do
if checkplayers() then
IntermissionTimer()
Map()
RoundTimer()
reloadAllPlayers()
destroyMap()
end
end
How would I implement that into my script?

1 comment
This is better than mine, please accept this one instead!