Question about tagging instances

Hey, so for my spectate system, I decided to use tagging (with CollectionService) to find all the participating players in the game. It worked good, however I wasn’t 100% sure how tags garbage collect.

Basically my question is this: Do tags on instances that have been destroyed garbage collect automatically when calling the :GetTagged() method? Because at one point one player dies, and the spectate system is throwing an error, where an index in the table is nil, so this made me wonder if the tagged instance still exists despite it getting destroyed.


1 Like

Tags don’t get deleted because they aren’t created in the first place. Tags from CollectionService are serialised on the instances themselves. Knowing whether a tag is deleted or not doesn’t matter because CollectionService is designed to create collections based on tags that you add to instances.

If an object is deleted or a tag is removed from the object, it will fire an instance removed signal which passes the object as an argument. You can connect various actions to occur by using GetInstanceRemovedSignal and passing the string of a tag.


1 Like