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- AddTag associates the string tag with the Coin instance.
- GetTagged returns all currently tagged instances, including ones elsewhere in the DataModel.
- 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