Here is the code:

local function runDropper(dropper)
	
	spawn(function()
		
		local loopWaitTime = dropper:WaitForChild("LoopWaitTime")
		local oreValue = dropper:WaitForChild("OreValue")
		local dropperPart = dropper:WaitForChild("DropperPart")
						
		if loopWaitTime and oreValue and dropperPart then
							
			local waitTime = loopWaitTime.Value
			local oreToClone = Instance.new("Part")
			local loopedTimes = 0
							
			while true do 
				
				wait(2)
				
				local newOre = oreToClone:Clone()
								
				newOre.Name = "Ore"
				newOre.Parent = dropper
				newOre.Size = Vector3.new(1, 1, 1)
				newOre.Position = dropperPart.Position
				
				game.Debris:AddItem(newOre, 20)
								
				local cash = Instance.new("NumberValue")
								
				cash.Name = "Cash"
				cash.Parent = newOre
				cash.Value = oreValue.Value
				
				loopedTimes = loopedTimes + 1
				
				print(loopedTimes)
										
			end	
		end
	end)
end

return runDropper

when I print loopedTimes it only prints: 1 Could someone tell me what is wrong? I have no idea. Thanks!

5 comments

0

Try adding the wait() between the while and do

0

What? That won't solve anything.

0

theCJarmy7 "while wait() do" is a shorthand of "while true do wait()" considering wait() only yeilds the code and not really anything else

0

if ANY error happens in the loop the script stops and the loop does not go anymore

0

I figured out the problem. That is why it says [Solved]