Dropper not dropping

I am following a tycoon series by B Ricey but the dropper stops dropping like it will drop once then stops

local dropsFolder = game:GetService("ServerStorage").Drops
local Debris = game:GetService("Debris")

local Dropper = {}
Dropper.__index = Dropper

function Dropper.new(tycoon, instance)
	local self = setmetatable({}, Dropper)
	self.Tycoon = tycoon
	self.Instance = instance
	self.Rate = instance:GetAttribute("Rate")
	self.DropTemplate = dropsFolder[instance:GetAttribute("Drop")]
	self.DropSpawn = instance.Spout.Spawn

	return self
end

function Dropper:Init()
	coroutine.wrap(function()
		while true do
			self:Drop()
			wait(self.Rate)
		end
	end)()
end

function Dropper:Drop()
	local drop = self.DropTemplate:Clone()
	drop.Position = self.DropSpawn.WorldPosition
	drop.Parent = self.Instance

	Debris:AddItem(drop, 5)
end

return Dropper
4 Likes

Since the dropper does spawn a cube successfully, this leads to self.Rate likely being the problem. Are you sure the value is not accidentally set to some high number?

1 Like

should the rate be lower? i have it at a high number

2 Likes

The rate determines the yield in seconds between each drop.

Update. @xiiitixxtxxtxxxxiiix you’re welcome!

In the coroutine, the while-loop can be broken down into steps.

  • While the condition is true (in case of while true we’re dealing with an infinite loop), keep calling the do-block.
    → Inside the do-block, call the method to spawn the drop and wait/yield the code.

Since the video was recorded about two years ago, there have been some small changes for the better.

wait() is a deprecated legacy object superceded by task.wait() from the task library.

Debris also relies on it internally, so it might want to replace it with task.delay() towards performance improvement.

task.delay(5, function()
	drop:Destroy()
end)

-- respectively
task.delay(5, workspace.Part.Destroy, workspace.Part)
2 Likes

oh thanks i thought it was like how many spawned

1 Like

Perhaps it has something to do with the coroutine as you aren’t resuming it.

function Dropper:Init()
	coroutine.resume(coroutine.wrap(function()
		while true do
			self:Drop()
			wait(self.Rate)
		end
	end)())
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.