Problem with AddTag

Hello, i’ve got a problem with the AddTag.
When i use the AddTag, the tag needs me to click him to Import, and this a problem because i can’t run the rest of the script. How i can solve this?

image

part = game.Workspace.horse

collection = game:GetService("CollectionService")

colocartag = collection:AddTag(part, "TestTag")

wait(5)

function duck()
	if collection:HasTag(part, "TestTag") then
		part:Destroy()
	end
end

duck()

1 Like

You made it a variable, consider removing the variable part of it, I would also recommend you using the local, as it makes your script run faster:
Change:

colocartag = collection:AddTag(part, "TestTag")

To:

collection:AddTag(part, "TestTag")

If you add the tag from studio you do not need to add it inside of the script you can just do this:

local part = game.Workspace.horse

local collection = game:GetService("CollectionService")

function duck()
	if collection:HasTag(part, "TestTag") then
		part:Destroy()
	end
end

duck()

But if you want to add the tag from inside of the script just do this:

local part = game.Workspace.horse

local collection = game:GetService("CollectionService")

collection:AddTag(part, "TestTag")

local function duck()
	if collection:HasTag(part, "TestTag") then
		part:Destroy()
	end
end

duck()

Note, all your code will do is destroy the part when it is executed.