Collapse Sidebar


HasTag returns whether a given object has a tag

  • Using CollectionService/AddTag to add the tag will cause this method to return true.
  • Using CollectionService/RemoveTag to remove the tag will cause this method to return false.

By extension, any tags returned by a call to CollectionServiec/GetTags on an object will return true when used with this method.


Name Type Default Description



Return Type Summary

Code Samples

Using Tags and CollectionService

This code sample demonstrates adding, removing and querying a tag from an object using CollectionService. Be sure to add a Part to the Workspace before running this code.

local CollectionService = game:GetService("CollectionService")
local object = workspace.Part

-- Add a tag
CollectionService:AddTag(object, "Deadly")

-- Query for a tag
if CollectionService:HasTag(object, "Deadly") then
	print(object:GetFullName() .. " is deadly")

-- List tags on an object
local tags = CollectionService:GetTags(object)
print("The object " .. object:GetFullName() .. " has tags: " .. table.concat(tags, ", "))

-- Remove a tag
CollectionService:RemoveTag(object, "Deadly")