How do I make this loop stop, then play?

How do I make this loop stop, then play every few seconds? Can someone fix this script?

local amount = 1000

local person = script.Parent.Parent
local cam = game.Workspace.CurrentCamera

repeat wait() until game.Workspace:findFirstChild(person.Name)~=nil
repeat wait() until game.Workspace:findFirstChild(person.Name):findFirstChild("Head")~=nil
local theperson = game.Workspace:findFirstChild(person.Name)

local head = game.Workspace:findFirstChild(person.Name):findFirstChild("Head")

local part ="Part")
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.5
part.BrickColor ="Pastel light blue")
part.TopSurface = "Smooth"
part.BottomSurface = "Smooth"
part.formFactor = "Custom"
part.Size =,1.2,.2)
local mesh ="BlockMesh")
mesh.Scale =,2,.4)
mesh.Parent = part

while true do
for i = 1, amount do
	local drop = part:Clone()

	function onHit(hit)

	drop.Parent = cam
	drop.CFrame = cam.CoordinateFrame *,50),math.random(80,110),math.random(-50,50))
	drop.Anchored = false

This is the part I want to modify:

The script goes in StarterGui Btw.


I dont see any script, maybe you pasted it wrong

1 Like

Sorry about that! Here’s the script!

1 Like

You can have a control variable outside of the loop like for example called paused and then in the loop you can have all of that loop code wrapped in an if which checks too see if paused isnt true and if it is then set it to false every few seconds

1 Like

first you can create an anonymous function, which means you don’t make a separate function for the hit event

    --this will run when the part is touched

next I would remove the while or for loop as it isn’t necessary.

for i=1, amount do
    --runs a set amount of times


while spawnParts do
    --runs indefinitely with a cooldown, without the cooldown the game will crash

you also forgot to parent the clone, which should be the last thing you do, as setting the properties while the part isn’t parented takes less memory

1 Like

What should the script look like then?

1 Like
local part = workspace.Part
local amount = 50
local pause = 5

while true do
	for i = 1, amount do wait(.03)
		local drop = part:Clone()
	     -- whatever you're doing here

1 Like

Soo, the problem is, you can’t stop the loop and then restart it without restarting loop from start, but if we have while loop, that have if condition inside of it, you can change condition to false, soo while loop will run, but the condition wiill block the function, then if you wan’t, set the value to true and then loop start, if you wan’t to break loop, set the main condition to false, soo loop will break permanently