CollectionService

CollectionService : Instance

Overview

A service that allows you to assign string-based tags to instances, making it easy to group and manage objects with similar properties.

Tags assigned on the server are automatically synchronized to clients, ensuring both sides maintain the same tag state.

Properties

Methods

AddTag

Adds a tag with the specified name to the target instance.

Parameters

instance instance

The target instance.

string tag

The name of the tag to assign.

Return

void

Code Samples

local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

CollectionService:AddTag(Part, "SomeTag")

GetTags

Returns an array of all tags applied to the target instance. Unlike HasTag(), which checks for a specific tag, it is ideal for retrieving all tags applied to an instance.

Parameters

instance instance

The target instance.

Return

Array

An array of strings.

Code Samples

local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

local Tags = CollectionService:GetTags(Part)
print(Tags)

HasTag

Returns true if the tag with the specified name is added to the target instance.

Parameters

instance instance

The target instance.

string tag

The name of the tag to check.

Return

bool

Specifies whether the tag exists.

Code Samples

local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

local hasTag = CollectionService:HasTag(Part, "SomeTag")
print(hasTag)

RemoveTag

Removes the tag with the specified name from the target instance, and operates without errors even if the tag does not exist.

Parameters

instance instance

The target instance.

string tag

The name of the tag to remove.

Return

void

Code Samples

local Part = script.Parent
local CollectionService = game:GetService("CollectionService")

CollectionService:RemoveTag(Part, "SomeTag")

Events

Last updated