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

(SOLVED) How do I temporarily disable a loop without breaking it?

Ok so I'm somewhat familiar with Lua, I'd say I'm somewhere between basic and intermediate. I'm making a machine that makes money then burns it (just for giggles). I'm just using it to test out certain codes and aspects I just recently learned. To make the money I'm using a while loop and Instancing. The code works fine. My problem started when I tried making an on/off button. I have a boolvalue located within the model named "Activated" and the while loop is dependent on that. i noticed the off button works (perhaps because it broke the loop) Is there a way to temporarily stop the loop without breaking it? In other words, how would I make my on button reactivate it.

This is the code that creates the money(yes i spelled conveyor wrong, don't roast ;-;)

active = game.Workspace.ConveryorBelt.Activated
testpart = game.Workspace.ConveryorBelt.Maker


while active.Value == true do
newpart = Instance.new("Part", game.Workspace.Money)	
newpart.BrickColor = BrickColor.new("Lime green")
newpart.Size = Vector3.new(1, .5, 2)
newpart.Position = testpart.Position
newpart.TopSurface = ("Smooth")
newpart.Name = ("Money")
wait(1)
end

And these are the codes that control the buttons and set the bool value to true/false

Off

active = game.Workspace.ConveryorBelt.Activated

function off ()
	active.Value = false
end

script.Parent.ClickDetector.MouseClick:Connect(off)

On


active = game.Workspace.ConveryorBelt.Activated


function on ()
	active.Value = true
end

script.Parent.ClickDetector.MouseClick:Connect(on)

6 comments

0

u put a wait() in da loop

0

also u r doing destruction of government property. By law, if the damage exceeds $100, the defendant is subject to a fine of up to $250,000, ten years imprisonment, or both. So watch out

0

There is a wait in da loop and also...I am the government >:)

0

dam

0

if there is wait() in da loop u should make da wait() longer

0

like, not 0

1 answer

i understand that this question is already solved. However as a fellow embassy of money i will give u a self assembling, legitimate money printer. This uses coroutines for the inner loop delay thingy that u probably is using in ur script lest it is indecent:

place in workspace:


 -- create basePart for printer to be situated around

local basePart = Instance.new("Part")
basePart.Anchored = true
basePart.CFrame = CFrame.new(0, .5, 0) -- here u say where u want the printer to be put at
basePart.Parent = workspace
basePart.Size = Vector3.new(1, 1, 1)

 -- systematically create part and its variables

local posList = {CFrame.new(-2, 0.5, 0), CFrame.new(-0.5, 2, 0), CFrame.new(-2, 1.75, 0), CFrame.new(-3.5, 2, 0) * CFrame.Angles(math.pi / 6, 0, 0), CFrame.new(-2, 2, 0) * CFrame.Angles(math.pi / 12, 0, 0)}
local sizeList = {Vector3.new(4, 2, 3), Vector3.new(1, 1, 3), Vector3.new(1, 1, 1), Vector3.new(1, 1, 3), Vector3.new(4, .1, 3)}

function slidePart(pos, size)
	local part = basePart:Clone()
	part.Anchored = true
	
	local startCF = part.CFrame * CFrame.new(math.random(0, 10), math.random(0, 10), math.random(0, 10))
	part.CFrame = startCF
	
	part.Parent = basePart
	part.Size = size
	
	for i = 1, 10, 1 do
		wait()
		
		part.CFrame = startCF:Lerp(basePart.CFrame * pos, i / 10)
	end
		
	return part
end

for i, v in pairs(posList) do
	local printerPart = slidePart(v, sizeList[i]) -- btw i aligned the posList with the sizeList for easy reference(boss move)
	
	if i == 3 then
		printerPart.Name = "moneyMaker"
		printerPart.CanCollide = false
		printerPart.Transparency = 1
	end
	
	wait(math.random(0, 30) / 10)
end

while true do
	wait(.1)
	
	 -- wrap money process in coroutine(make process run alongside script so the wait()s inside the process will have no affect to the script)
	
	coroutine.resume(coroutine.create(function()
		
		 -- create money(i approve)
		
		local money = basePart.moneyMaker:Clone()
		money.Anchored = false
		money.BrickColor = BrickColor.new("Sage green")
		money.CanCollide = true
		money.Parent = workspace
		money.Size = Vector3.new(1, .2, 2)
		money.Transparency = 0
		money.Velocity = money.CFrame.LookVector * 30
		
		wait(.3)
		
		 -- make money burn(i do not approve)
		
		local fire = Instance.new("Fire")
		fire.Parent = money
		
		wait(.1)
		
		 -- make money turn bad(i do not approve)
		
		local startC3 = Color3.fromRGB(0, 0, 0)
		local goalC3 = Color3.fromRGB(255, 255, 255)
		
		for i = 1, 10, 1 do
			wait()
			
			money.Color = startC3:Lerp(goalC3, i / 10)
		end
		
		 -- destroy money(i do not approve)
		
		money:Destroy()
	end))
end

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