I am trying to make a game with rounds and a intermission and then regenerate the map but idk how to fix this. Here is my script.
local RoundLength = 10 -- How long the rounds are in seconds. local IntermissionLength = 5 -- How long the intermission is in seconds. local RoundStartTime -- To tell when the round starts. local map = game.workspace.Map local function initialize() local MapCopy = map:Clone()-- A copy of the map MapCopy.Name = "MapCopy" MapCopy.Parent = game.Workspace RoundStartTime = tick() -- Tick = What current time is in seconds. end local function cleanup() game.Workspace.MapCopy:Destroy() end map.Parent = game.ServerStorage while true do initialize()-- Puts current time in round start time. repeat local CurrentTime = tick() local TimeSinceGameStarted = CurrentTime - RoundStartTime until TimeSinceGameStarted > RoundLength cleanup() wait(IntermissionLength) end
Your main problem was because repeat didn't have a wait. Repeat is a loop, if it doesn't have a wait, like a while statement, it will crash or force a break request to happen in studio.
local RoundLength = 10 -- How long the rounds are in seconds. local IntermissionLength = 5 -- How long the intermission is in seconds. local RoundStartTime -- To tell when the round starts. -- Use WaitForChild() on children -- Why not just put this in ServerStorage off the bat? local map = workspace:WaitForChild("Map") map.Parent = game:GetService("ServerStorage") local function initialize() local MapCopy = map:Clone()-- A copy of the map MapCopy.Name = "MapCopy" MapCopy.Parent = game.Workspace RoundStartTime = tick() -- Tick = What current time is in seconds. -- returns your cloned map so we can use it later, rather than trying to -- find it again return MapCopy end local function cleanup(this_map) this_map:Destroy() end while true do local this_map = initialize()-- Puts current time in round start time. -- repeat is a loop, so it needs a wait repeat wait() local CurrentTime = tick() local TimeSinceGameStarted = CurrentTime - RoundStartTime print(TimeSinceGameStarted) until TimeSinceGameStarted > RoundLength cleanup(this_map) wait(IntermissionLength) end