Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I fix this?

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

1 comment

0

use .Workspace instead of .workspace :Remove() instead of :Destroy() (this isnt a solution, just some tips)

1 answer

✓ Accepted answer

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

7 comments

0

still dint work :(

0

Works for me, check the output.

0

ok

0

could you possibly come see my game and tell me whats wrong?

0

You need a wait in the while loop too, and the repeat loop.

0

ok thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.