GetTagged returns a table of objects with a given tag which are descendants of the
game). Such tags have been added using
CollectionService/AddTag, and removing a tag using
CollectionService/RemoveTag will ensure this method does not return them. Although the name of this method is past-tense, this method only returns objects presently tagged with the given tag. It will not return objects that once had a tag but no longer have it.
If you want to detect all objects with a tag, both present and future, use this method to iterate over objects while also making a connection to a signal returned by
This method does not guarantee any ordering of the returned objects. Additionally, it is possible that objects can have the given tag assigned to them, but not be a descendant of the
DataModel, i.e. its parent is nil. This method will not return such objects.
Deadly Bricks using CollectionService
This code sample causes any
BasePart with the tag “Deadly” to kill any
Humanoid that touches it. It does this using a common pattern with
CollectionService: listen for all parts with the tag, and make a connection. When the tag is removed, disconnect. Instead of copying the same kill script into many bricks, use this pattern instead!