GetInstanceAdded is given a tag (a string) and returns a signal which fires under two conditions:
- The tag is assigned to an object within the
- An object with the given tag is added as a descendant of the
DataModel, e.g. by setting
Subsequent calls to this method with the same tag return the same signal object. Consider also calling
CollectionService/GetTagged to get a list of objects that already have a tag (and thus won’t fire the event if they already are in the
CollectionService/GetInstanceRemovedSignal, which returns an event that fires under similar conditions.
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!