Can I get a new eyes on this logic issue?

Hello everyone, I am working on a system and using something called “components” basically it is a modular class that runs on objects tagged with CollectionService and just wondering what is going on here.

When a new item is tagged it gets added to a table for later reference and calls its functions

local function component_added(item)
		local c = module.new(item)
		babies[item] = c
end
local function component_removed(item)
		local babyModule = babies[item]

		if babyModule ~= nil then
			if babyModule.Clean ~= nil then
				babyModule:Clean()
			end
			babies[item] = nil
		end
end

The system works great the first time, but the second time it doesn’t and I have found the issue, in this function above, the “item” is nil.

These functions are just connected to their relative “GetInstance___Signal” event.

The important component functions information looks like so:

function Buildable.new(instance: Instance)
	local self = setmetatable({
		["_initialized"] = false,
		["Instance"] = instance,
		["Maid"] = loader.Maid(),
	}, Buildable)

	self:_init()
	return self
end
function Buildable:_init()
    ...
	self.Maid:GiveTask(self.Instance:GetAttributeChangedSignal("Attack"):Connect(function()
		CollectionService:RemoveTag(self.Instance, "Buildable")
	end))
end

And the clean up function:

function Buildable:Clean()
	print("Cleaning Buildable")
	self.Maid:DoCleaning()
    ...
	self.Instance:SetAttribute("Attack", false)
	CollectionService:AddTag(self.Instance, "Buildable")
end

Are you supposed to be adding the buildable to the collection service when calling :Clean()? If so, which metamethods are you using? Could you show your full buildable module?

Component runs the .new, which runs init to whatever object gets the tag name, and component removed calls :Clean. Buildable is a component module so I think you want my component manager.
Here is the loading function:

local function load(source)
	for _, component in source do
		local module_name = component.Name
		local module = require(component)
		local tag = module.Tag

		assert(tag ~= nil, ("[ComponentManager] Module '%s' does not have a tag."):format(module_name))
		assert(Children[tag] == nil, ("[ComponentManager] Overlapping tag: '%s'"):format(tag))

		local babies = {}
		Children[tag] = babies

		local function component_added(item)
			local c = module.new(item)
			babies[item] = c
		end

		local function component_removed(item)
			local babyModule = babies[item]

			if babyModule ~= nil then
				if babyModule.Clean ~= nil then
					babyModule:Clean()
				end
				babies[item] = nil
			end
		end

		CollectionService:GetInstanceAddedSignal(tag):Connect(component_added)
		for _, item in ipairs(CollectionService:GetTagged(tag)) do
			component_added(item)
		end
		CollectionService:GetInstanceRemovedSignal(tag):Connect(component_removed)
	end
end