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.

1 comment
add a loop twice that way it will go to the previous loop and check if roundactive is true again and wont continue after line 22. do what the guy who answered did