Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
CollectionService
Inherits from: Instance → Object
CollectionService manages groups (collections) of instances with tags. Tags are sets of strings applied to instances that replicate from the server to the client. They are also serialized when places are saved.
The primary use of CollectionService is to register instances with specific tags that you can use to extend their behavior. If you find yourself adding the same script to many different instances, a script that uses CollectionService may be better.
Tags can be added or removed through this class' methods such as AddTag() or RemoveTag(). They can also be managed directly in Studio through the Tags section of an instance's properties.
Replication
When tags replicate, all tags on an instance replicate at the same time. Therefore, if you set a tag on an instance from the client then add/remove a different tag on the same instance from the server, the client's local tags on the instance are overwritten. In StreamingEnabled places, instances can be unloaded as they leave the client's streamed area. If such an instance re-enters the streamed area, properties and tags will be re-synchronized from the server. This can cause changes made by LocalScripts to be overwritten/removed.
Inherits from: Instance
Memory category: Instances
Tags: NotCreatable, Service
Methods
| Name | Type / Returns | Description |
|---|---|---|
| CollectionService:AddTag | () | Applies a tag to an Instance. |
| CollectionService:CreateCollection | Collection | Creates a Collection that tracks every instance matching a query. |
| CollectionService:GetAllTags | Array | Returns an array of all tags in the experience. |
| CollectionService:GetCollection | Instances | Returns all instances of a given class which are in the DataModel. |
| CollectionService:GetInstanceAddedSignal | RBXScriptSignal | Returns a signal that fires when a given tag is added to an instance. |
| CollectionService:GetInstanceRemovedSignal | RBXScriptSignal | Returns a signal that fires when a given tag is removed from an instance. |
| CollectionService:GetTagged | Instances | Returns an array of instances in the game with a given tag. |
| CollectionService:GetTags | Array | Gets an array of all tags applied to a given instance. |
| CollectionService:HasTag | boolean | Check whether an instance has a given tag. |
| CollectionService:RemoveTag | () | Removes a tag from an instance. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance:AddTag | () | Applies a tag to the instance. |
| Instance:children | Instances | Returns an array of the object's children. |
| Instance:ClearAllChildren | () | This method destroys all of an instance's children. |
| Instance:Clone | Instance | Create a copy of an instance and all its descendants, ignoring instances that are not Archivable. |
| Instance:clone | Instance | |
| Instance:Destroy | () | Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children. |
| Instance:destroy | () | |
| Instance:FindFirstAncestor | Instance? | Returns the first ancestor of the Instance whose Instance.Name is equal to the given name. |
| Instance:FindFirstAncestorOfClass | Instance? | Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className. |
| Instance:FindFirstAncestorWhichIsA | Instance? | Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstChild | Instance? | Returns the first child of the Instance found with the given name. |
| Instance:findFirstChild | Instance | |
| Instance:FindFirstChildOfClass | Instance? | Returns the first child of the Instance whose ClassName is equal to the given class name. |
| Instance:FindFirstChildWhichIsA | Instance? | Returns the first child of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstDescendant | Instance? | Returns the first descendant found with the given Instance.Name. |
| Instance:GetActor | Actor? | Returns the Actor associated with the Instance, if any. |
| Instance:GetAttribute | Variant | Returns the value which has been assigned to the given attribute name. |
| Instance:GetAttributeChangedSignal | RBXScriptSignal | Returns an event that fires when the given attribute changes. |
| Instance:GetAttributes | Dictionary | Returns a dictionary of the instance's attributes. |
| Instance:GetChildren | Instances | Returns an array containing all of the instance's children. |
| Instance:getChildren | Instances | |
| Instance:GetDebugId | string | Returns a coded string of the debug ID used internally by Roblox. |
| Instance:GetDescendants | Instances | Returns an array containing all of the descendants of the instance. |
| Instance:GetFullName | string | Returns a string describing the instance's ancestry. |
| Instance:GetStyled | Variant | Returns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified. |
| Instance:GetStyledPropertyChangedSignal | RBXScriptSignal | Returns an event that fires when the given style property changes on the instance. |
| Instance:GetTags | Array | Gets an array of all tags applied to the instance. |
| Instance:HasTag | boolean | Check whether the instance has a given tag. |
| Instance:IsAncestorOf | boolean | Returns true if an Instance is an ancestor of the given descendant. |
| Instance:IsDescendantOf | boolean | Returns true if an Instance is a descendant of the given ancestor. |
| Instance:isDescendantOf | boolean | |
| Instance:IsPropertyModified | boolean | Returns true if the value stored in the specified property is not equal to the code-instantiated default. |
| Instance:QueryDescendants | Instances | Returns an array containing all descendants of the instance that match the selector string. |
| Instance:Remove | () | Sets the object's Parent to nil, and does the same for all its descendants. |
| Instance:remove | () | |
| Instance:RemoveTag | () | Removes a tag from the instance. |
| Instance:ResetPropertyToDefault | () | Resets a property to its default value. |
| Instance:SetAttribute | () | Sets the attribute with the given name to the given value. |
| Instance:WaitForChild | Instance | Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object:GetPropertyChangedSignal | RBXScriptSignal | Get an event that fires when a given property of the object changes. |
| Object:IsA | boolean | Returns true if an object's class matches or inherits from a given class. |
| Object:isA | boolean |
CollectionService:AddTag
This method applies a tag to an Instance, doing nothing if the tag is already applied to that instance. Successfully adding a tag will fire a signal created by GetInstanceAddedSignal() with the given tag.
Warnings
An instance's tags that were added client-side will be dropped if the server later adds or removes a tag on that instance because the server replicates all tags together and overwrites previous tags.
When tagging an instance, it is common that some resources are used to give the tag its functionality, for example event connections or tables. To prevent memory leaks, it's a good idea to clean these up (disconnect, set to
nil, etc.) when no longer needed for a tag. Do this when callingRemoveTag(), callingInstance:Destroy()or in a function connected to a signal returned byGetInstanceRemovedSignal().
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The Instance to apply the tag to. | |
| tag | string | The tag string to apply to the instance. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| tags | ["CustomLuaState"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
CollectionService:CreateCollection
This method creates a Collection, a live, query-based group of instances. Unlike tag-based methods such as GetTagged() which return a fixed array at the moment they are called, a Collection continuously tracks which instances match query and notifies you as instances enter and leave the result set.
The query string is a CSS-inspired selector that follows the same selector conventions used by QueryDescendants() and the StyleRule styling selectors. Filters stack conjunctively, combinators express hierarchy, and comma-separated selectors form a union:
ClassName— Instances of that class (usesIsA()), for examplePartorModel.#Name— Instances with a matchingName..Tag— Instances carrying aCollectionServicetag.[Property = value]— Instances whose property equals a value.[$Attribute]or[$Attribute = value]— Instances that have an attribute, optionally matching a value.A > B(direct child) andA >> B(any descendant) combinators.:has(...)and:not(...)pseudoclasses.
The rightmost selector in a chain identifies the matched instance, so Folder > Part tracks the parts, not the folders.
local CollectionService = game:GetService("CollectionService")
-- Track every Part tagged "KillBrick" anywhere under Workspace
local killBricks: Collection = CollectionService:CreateCollection("Part.KillBrick")
-- When a part joins the collection, make it glow red
-- OnAdded fires once for each part already matching, then again for each new match
function killBricks.OnAdded(brick: Part)
brick.Material = Enum.Material.Neon
brick.Color = Color3.new(1, 0, 0)
end
-- Kill any humanoid that touches a matched part
function killBricks.OnTouched(brick: Part, otherPart: BasePart)
local character: Instance? = otherPart.Parent
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- Fires when a part stops matching (tag removed, reparented out, or destroyed)
function killBricks.OnRemoved(brick: Part)
print("Deactivating", brick:GetFullName())
end Notes
- The collection remains active until you call
Destroy()or itsrootis destroyed. - Lifecycle callbacks are queued rather than invoked synchronously, so a newly assigned
OnAddedmay fire on a later resumption point rather than during the assignment itself.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| query | string | A selector string describing which instances to match. See the description for the supported syntax. | |
| root | Instance | nil | The instance whose descendants are searched. Pass this to restrict the search to a subtree, such that instances outside that subtree never match and an instance is removed from the collection if it is reparented out of root. Defaults to Workspace when omitted. |
Returns
| Type | Description |
|---|---|
| Collection | A Collection that reactively tracks the instances matching query. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
CollectionService:GetAllTags
Returns an array of all tags that currently have at least one tagged instance inside the DataModel. The returned array does not guarantee any particular ordering.
A tag appears in the result as soon as any instance bearing it enters the DataModel (for example by being parented to Workspace), and it is removed from the result once the last instance with that tag leaves the DataModel or has the tag removed. This means calling GetAllTags() immediately after removing the last instance with a given tag will no longer include that tag.
Returns
| Type | Description |
|---|---|
| Array | An array of all tags that currently have at least one tagged instance in the DataModel. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Safe |
| capabilities | ["Basic"] |
CollectionService:GetCollection
Deprecated. This item has been superseded by a CollectionService tagging method. The equivalent function using the new method is CollectionService:GetTagged() which should be used in new work.
This function returns all instances of a given class which are in the DataModel. Only works for Configuration, CustomEvent, CustomEventReceiver, Dialog, and VehicleSeat.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| class | string | The class type to retrieve instances of. |
Returns
| Type | Description |
|---|---|
| Instances | An array of all instances of the specified class in the DataModel. |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (CollectionService-GetCollection1).
CollectionService:GetInstanceAddedSignal
Given a tag (string), this method returns a signal which fires under two conditions:
The tag is assigned to an instance within the
DataModelusingCollectionService:AddTag()orInstance:AddTag().An instance with the given tag is added as a descendant of the
DataModel, for example by settingInstance.Parentor similar.
Subsequent calls to this method with the same tag return the same signal object. Consider also calling GetTagged() to get a list of instances that already have a tag (and thus won't fire the event if they already are in the DataModel).
See also GetInstanceRemovedSignal() which returns an event that fires under similar conditions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| tag | string | The tag to watch for. |
Returns
| Type | Description |
|---|---|
| RBXScriptSignal | An event that fires when you add the tag to an instance. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Deadly-Bricks-using-CollectionService).
CollectionService:GetInstanceRemovedSignal
Given a tag (string), this method returns a signal which fires under two conditions:
The tag is removed from an instance within the
DataModelusingCollectionService:RemoveTag()orInstance:RemoveTag().An instance with the given tag is removed as a descendant of the
DataModel, for example by un‑settingInstance.Parentor similar.
Subsequent calls to this method with the same tag return the same signal object. The signal is useful for cleaning up resources used by instances that once had tags, such as disconnecting connections.
See also GetInstanceAddedSignal() which returns an event that fires under similar conditions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| tag | string | The tag to watch for. |
Returns
| Type | Description |
|---|---|
| RBXScriptSignal | An event that fires when you remove the tag from an instance. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Deadly-Bricks-using-CollectionService).
CollectionService:GetTagged
This method returns an array of instances with a given tag which are descendants of the DataModel. Removing a tag using CollectionService:RemoveTag() or Instance:RemoveTag() ensures this method does not return them.
If you want to detect all instances with a tag, both present and future, use this method to iterate over instances while also making a connection to a signal returned by GetInstanceAddedSignal().
This method does not guarantee any ordering of the returned instances. Additionally, it's possible that instances can have the given tag assigned to them but not be a descendant of the DataModel, for example its parent is nil; this method will not return such instances.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| tag | string | The tag to search for. |
Returns
| Type | Description |
|---|---|
| Instances | An array of all instances with the tag. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Safe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Deadly-Bricks-using-CollectionService).
CollectionService:GetTags
Given an Instance, this method returns an array of strings which are the tags applied to the instance.
This method is useful when you want to do something with multiple instance tags at once, but it's inefficient to check for the existence of a single tag. For this, use HasTag() to check for a single tag.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The instance whose tags should be returned. |
Returns
| Type | Description |
|---|---|
| Array | An array of strings which are the tags applied to the given instance. |
| Field | Value |
|---|---|
| tags | ["CustomLuaState"] |
| security | None |
| thread safety | Safe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Using-Tags-and-CollectionService).
CollectionService:HasTag
This method returns whether a given Instance has a tag.
By extension, any tags returned by a call to GetTags() on an instance will return true when used with this method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The instance to check for the presence of a tag. | |
| tag | string | The tag to check for. |
Returns
| Type | Description |
|---|---|
| boolean | Whether the instance has the tag. |
| Field | Value |
|---|---|
| tags | ["CustomLuaState"] |
| security | None |
| thread safety | Safe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Using-Tags-and-CollectionService).
CollectionService:RemoveTag
This method removes a tag from an instance. Successfully removing a tag will fire a signal created by GetInstanceRemovedSignal() with the given tag.
When removing a tag, it's common that some resources are used to give the tag its functionality, for example event connections or tables. To prevent memory leaks, it's a good idea to clean these up (disconnect, set to nil, etc.) when no longer needed for a tag.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The instance to remove the tag from. | |
| tag | string | The tag to remove from the instance. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| tags | ["CustomLuaState"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (Using-Tags-and-CollectionService).
Events
| Name | Type / Returns | Description |
|---|---|---|
| CollectionService.ItemAdded | Fires when a Configuration, CustomEvent, CustomEventReceiver, Dialog, or VehicleSeat is added to the DataModel. | |
| CollectionService.ItemRemoved | Fires when a Configuration, CustomEvent, CustomEventReceiver, Dialog, or VehicleSeat is removed from the DataModel. | |
| CollectionService.TagAdded | Fires when a tag is added to an instance and the added tag is the only occurrence of that tag in the place. | |
| CollectionService.TagRemoved | Fires when a tag is removed from an instance and the removed tag is no longer used anywhere in the place. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.AncestryChanged | Fires when the Instance.Parent property of this object or one of its ancestors is changed. | |
| Instance.AttributeChanged | Fires whenever an attribute is changed on the Instance. | |
| Instance.ChildAdded | Fires after an object is parented to this Instance. | |
| Instance.childAdded | ||
| Instance.ChildRemoved | Fires after a child is removed from this Instance. | |
| Instance.DescendantAdded | Fires after a descendant is added to the Instance. | |
| Instance.DescendantRemoving | Fires immediately before a descendant of the Instance is removed. | |
| Instance.Destroying | Fires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy(). | |
| Instance.StyledPropertiesChanged | Fires whenever any style property is changed on the instance, including when a property is set to nil. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.Changed | Fires immediately after a property of the object changes, with some limitations. |
CollectionService.ItemAdded
Deprecated. This item has been superseded by a CollectionService tagging method. There is currently no means of checking when a tag is added.
This function fires when a Configuration, CustomEvent, CustomEventReceiver, Dialog, or VehicleSeat is added to the DataModel.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The instance that was added to the DataModel. |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (CollectionService-ItemAdded1).
CollectionService.ItemRemoved
Deprecated. This item has been superseded by a CollectionService tagging method. There is currently no means of checking when a tag is removed.
This function fires when a Configuration, CustomEvent, CustomEventReceiver, Dialog, or VehicleSeat is removed from the DataModel.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| instance | Instance | The instance that was removed from the DataModel. |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| capabilities | ["Basic"] |
Code samples: View on Creator Hub (CollectionService-ItemRemoved1).
CollectionService.TagAdded
This event fires when a tag transitions from being unused to being in use — specifically, when a tag is applied to an instance inside the DataModel and no other instance in the DataModel previously had that tag. The event passes the tag name as its parameter.
TagAdded fires once per tag lifetime, not once per instance. To detect every individual instance that receives a particular tag, use GetInstanceAddedSignal() instead.
The event fires asynchronously (deferred to the next resumption point), not synchronously inside the AddTag() call that triggered it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| tag | string | The name of the tag that entered use. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Basic"] |
CollectionService.TagRemoved
This event fires when the last instance bearing a given tag leaves the DataModel or has the tag removed, meaning no instance in the DataModel still carries that tag. The event passes the tag name as its parameter.
TagRemoved fires once per tag lifetime, not once per instance. To detect every individual instance that loses a particular tag, use GetInstanceRemovedSignal() instead.
The event fires asynchronously (deferred to the next resumption point), not synchronously inside the removal operation that triggered it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| tag | string | The name of the tag that is no longer in use. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Basic"] |
Properties
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.Archivable | boolean | Determines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published. |
| Instance.archivable | boolean | |
| Instance.Capabilities | SecurityCapabilities | The set of capabilities allowed to be used for scripts inside this container. |
| Instance.IsInSandbox | boolean | Indicates whether the instance is inside a sandboxed container. |
| Instance.Name | string | A non-unique identifier of the Instance. |
| Instance.Parent | Instance | Determines the hierarchical parent of the Instance. |
| Instance.PredictionMode | PredictionMode | Reflects the client-side prediction mode applied to the instance under server-authoritative physics. |
| Instance.RobloxLocked | boolean | A deprecated property that used to protect CoreGui objects. |
| Instance.Sandboxed | boolean | When enabled, the instance can only access abilities in its Capabilities list. |
| Instance.UniqueId | UniqueId | A unique identifier for the instance. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.ClassName | string | A read-only string representing the class this Object belongs to. |
| Object.className | string |