Codectionary / Developer documentation / Luau

CollectionService tags

Label instances and find all objects that share a behavior.

Why use CollectionService?

Tags group instances without requiring them to share one Folder or Model. A script can find all tagged objects and attach the same logic to each one.

Try it in Roblox Studio

Create a BasePart named Coin in Workspace. Put this Script in ServerScriptService and inspect the output.

Syntax

CollectionService:AddTag(instance, "Collectible")

Examples

CollectionService tags

Tag one part and list matching objects.

local CollectionService = game:GetService("CollectionService")
local coin = workspace:WaitForChild("Coin")
assert(coin:IsA("BasePart"))
CollectionService:AddTag(coin, "Collectible")

for _, item in CollectionService:GetTagged("Collectible") do
    print(item:GetFullName())
end
  1. AddTag associates the string tag with the Coin instance.
  2. GetTagged returns all currently tagged instances, including ones elsewhere in the DataModel.
  3. For objects added later, use the service’s instance-added signal instead of assuming one initial list stays current.

Best practices

  • Use one clearly defined meaning per tag.
  • Validate instance type before applying behavior to every tagged object.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading