How do I add tags with a script? CollectionService

I’m trying to add a tag using collection services.
How do I do this.
This is what I have

local cs = game:GetService('CollectionService')
cs:AddTag(Obj)

I just need to figure out how I add the tag part I got the object.

1 Like

To Add tags, you need:

  • An Instance
    this is for CollectionService to know what you want to tag
  • And the tag
    The Second Argument is the tags name, so you can get the Instance access it later
local cs = game:GetService('CollectionService')
cs:AddTag(Instance, "myTag")

here, you have a tag called myTag assigned to an Instance

If you have multiple Objects under the same tag (aka myTag) , you could do this:

for num, Items in pairs(cs:GetTagged("myTag")) do -- Iterates through Objects with Tag
   -- You are able to edit multiple Objects under this tag
end

To Remove a Tag, you would do the same as AddTag:

cs:RemoveTag(Instance, "myTag")

CollectionService

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.