I’m using CollectionService as a performant way to keep track of all current Characters in my game.
When an instance (the character) with a tag gets :Destroy()
ed or parented to nil, is the tag removed and wiped, or is it still there, and do I have to use CollectionService:GetInstanceRemovedSignal()
?
The tag will be there but the tagged part will not, so if there were 3 parts tagged there is now 2. CollectionService:GetInstanceRemovedSignal()
fires when the instance is parented to nil or destroyed.
1 Like
So when the character resets and the old character is destroyed and the new one spawns in, the old character’s tag gets removed, correct?
1 Like
I don’t know the answer to your question, but I know how you can test it.
local part = Instance.new("Part", workspace)
local collection = game:GetService("CollectionService")
collection:AddTag(part, "Test")
part:Destroy()
print(collection:HasTag(part, "Test"))
--If false, then the tag is automatically removed
1 Like
Yes, the old characters tag will be removed.
1 Like
Did a quick test using the following:
local part = Instance.new("Part", workspace)
local collection = game:GetService("CollectionService")
collection:GetInstanceRemovedSignal('Test'):Connect(function()
print('instance was removed')
collection:RemoveTag(part, 'Test')
end)
collection:AddTag(part, "Test")
part:Destroy()
print(collection:HasTag(part, "Test"))
--If false, then the tag is automatically removed
Without CollectionService:RemoveTag(), the print will return true and the tag will still be there. In order to fully remove the tag you have to connect it to collection:GetInstanceRemovedSignal
and Destroy it.