I'm trying to make a code that clones a part called "Gobbler" every few seconds using a while loop. Every round the value of roundActive is temporarily set to false and then changed back to true. And the map is destroyed and then cloned back again. But for some reason, the while loop seems to only work the first round (the first time the value of roundActive is changed to true) and not for any other round (after it has temporarily been set to false). During the second round though, it seems like it clones the gobbler once for some reason.
wait(5) local gobbler = game.Workspace.map1:WaitForChild("Gobbler") local backup = gobbler:Clone() local difficulty = game.Workspace.Difficulty local roundActive = game.Workspace.RoundActive while roundActive.Value == true do if roundActive.Value == true then if difficulty.Value < 10 then wait(10 - difficulty.Value) gobbler = backup:Clone() gobbler.Parent = game.Workspace.map1 gobbler.Position = Vector3.new(0, 64, 0) else wait(10 / difficulty.Value) gobbler = backup:Clone() gobbler.Parent = game.Workspace.map1 gobbler.Position = Vector3.new(0, 64, 0) end end end
I am pretty sure it is this code that's the problem, since the value of roundActive is being changed, and this is the code that actually clones the gobblers, but I might be wrong. Please tell me if you think there might be some other code that causes the error.
try this instead:
while true do wait(0.5) while roundActive.Value == true do if roundActive.Value == true then if difficulty.Value < 10 then wait(10 - difficulty.Value) gobbler = backup:Clone() gobbler.Parent = game.Workspace.map1 gobbler.Position = Vector3.new(0, 64, 0) else wait(10 / difficulty.Value) gobbler = backup:Clone() gobbler.Parent = game.Workspace.map1 gobbler.Position = Vector3.new(0, 64, 0) end end end end