Attempt to index nil with 'DropTemplate' problem

Im trying to create a dropper in a tycoon game but im getting the error "attempt to index nil with ‘dropTemplate’ " because of line 12 and i dont know why. The Attribute in question is named Acacia and should be getting the part named Acacia

image

ive already tried replacing the brackets with :FindFirstChild and :WaitForChild but it creates the same error

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, 10)
end

return Dropper

Please Help!

My only assumption that it could be is that you’re calling Drop with a . instead of a :, the colon automatically passes in self whereas with a . you have to pass it in yourself, hence why it sees self as nil,

Try changing self.Drop() to self:Drop()

2 Likes