Using CollectionService to get all objects in a specified folder

From what I understand, CollectionService can be used to get ALL objects with a specific tag in a place.

What I am attempting to do with it is get all of the objects with a specific tag in a specific folder. I have had no luck in finding a solution for this.

Example:

local CollectionService = game:GetService("CollectionService")

local folder = workspace.Folder

CollectionService:GetTaggedDescendants(ancestor: Instance, tag: string)

Obviously :GetTaggedDescendants is not a real method of CollectionService, but that is essentially what I am trying to do.

Let me know if something is unclear or you need something else from me. If you have any ideas they would be much appreciated. Thanks!

Since you know which folder to look through, you can do a regular loop on it and then individually check if Instance:HasTag() returns true for each Instance:

Example

local folder = workspace.Folder

for _, item in folder:GetDescendants() do
    if item:HasTag("TagName") then
        print(item.Name.." has the 'TagName' CollectionService Tag!")
        -- Continue
    end
end
1 Like