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
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?
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.