CollectionService Code Samples don't connect the onInstanceAdded function

The following Developer Hub articles don’t utilise the CollectionService properly:

CollectionService/GetTagged
CollectionService/GetInstanceAddedSignal
CollectionService/GetInstanceRemovedSignal

In all of these articles, the onInstanceRemoved function is never called - even for the documentation of GetInstanceRemovedSignal, which it is intended for.

local function onInstanceRemoved(object)
	-- If we made a connection on this object, disconnect it (prevent memory leaks)
	if connections[object] then
		connections[object]:disconnect()
		connections[object] = nil
	end
end

The function is there, however it is never connected to an event. The solution would be to use the event signal this is intended to be connected to:

CollectionService:GetInstanceRemovedSignal(tag):Connect(onInstanceRemoved)
5 Likes

I completely agree. Some of the Developer tutorials on Roblox currently are extremely outdated, and confusing, whilst providing no help whatsoever to that subject for anyone attempting to learn.

Good find Web.

2 Likes

Another good example would be the “How to make a Laser Gun” to which they don’t explain at all how to make the gun FE compatible.