Issue With Using CollectionService

Hey, so I know how to use CollectionService, that’s all fine, but I have a bit of a problem.

Suppose I wanted to tag instances in my game with the tag “Door” when my game first ran. Rather than just naming them something identifiable as such, is there no way to reliably tag instances in studio itself without using ValueObjects?

Currently, I just throw a ValueObject inside of the instance, name it Door, iterate through everything in the workspace and if it’s a ValueObject with the name Door, I use CollectionService to tag it as Door.

Is there a better way to handle this? How should I go about solving this? Or is the way I’m currently doing it correct? If there’s a more elegant solution to this problem, I’d love to know.

I suspect you want to tag them all in order to use GetTagged(), but why bother with that, when you can just put all the doors inside a folder named Doors?

There’s a plugin to add tags while studio is not running, it’s really helpful go check it out

Hey, thanks for your reply.

This honestly looks great - so basically this thing just assigns tags to every part you assign using it? That’s cool, but does it create a script or something that just runs when the game starts?

Nope, it just uses something similar to the command bar to tag parts when studio is not running.

Try it out add a random part in your workspace and copy and paste this into your command bar:

local CollectionService = game:GetService("CollectionService")
CollectionService:AddTag(workspace.Part,"RandomPart")
print(CollectionService:GetTagged("RandomPart"))

You will get the Part instance as expected, now try running it without adding the tag:

local CollectionService = game:GetService("CollectionService")
print(CollectionService:GetTagged("RandomPart"))

You will still be able to print out the exact same part. With the newer output you can click the table instance to get the part which you tagged.

That’s very cool. I wasn’t aware that CollectionService tags actually saved; I just assumed they were all saved in a dictionary that was created when the game ran, and gc’ed when the game closed. Thanks!