So Im using CollectionService, and I have a tag with collection service, however how do I do an if statement checking if a part has a certain tag?
Please look up stuff before asking on here, you should be able to find an answer much quicker.
11 Likes
CollectionService:GetTags(Instance)
Did you seriously not read the documentation provided for you? It’s like the third line.
...:HasTag(tagName: string) -> boolean
2 Likes
To check if a part has a specific tag, you can use the Instance:HasTag() method.
local CollectionSerivce:GetService("CollectionService")
local SPECIFIC_TAG = "MyTag"
local part = some.Path.To.Part
local doesPartHaveSpecificTag = part:HasTag(SPECIFIC_TAG)
print(doesPartHaveSpecificTag) --> `true` if part has tag "MyTag", otherwise `false`
To check if a part has any tag, you can check that the number of (#) tags on a part (Instance:GetTags()) is more than (>) 0.
local CollectionSerivce:GetService("CollectionService")
local part = some.Path.To.Part
local doesPartHaveAnyTag = #part:GetTags() > 0
print(doesPartHaveAnyTag) --> `true` if part has any tag, otherwise `false`
3 Likes