Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I fix this?

Asked by 6 years ago
Edited 6 years ago

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
0
use .Workspace instead of .workspace :Remove() instead of :Destroy() (this isnt a solution, just some tips) Viking359 161 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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
0
still dint work :( Gusookey -3 — 6y
0
Works for me, check the output. Azarth 3141 — 6y
0
ok Gusookey -3 — 6y
0
could you possibly come see my game and tell me whats wrong? Gusookey -3 — 6y
View all comments (3 more)
0
You need a wait in the while loop too, and the repeat loop. hiimgoodpack 2009 — 6y
0
ok thank you Gusookey -3 — 6y
Ad

Answer this question