When I equip a tool with a CollectionService tag on it and I am not the first client to connect to the game, the CollectionService tag gets removed
Below are GIFs of the issue (look at the output window and when I equip the tool). The GIFs are from test servers inside of studio but I am pretty sure this happens in live servers as well from my testing
I have the following in the place file in the GIFs:
A Tool in StarterPack
A LocalScript in StarterCharacterScripts with the following code:
local collectionService = game:GetService("CollectionService")
local player = game.Players.LocalPlayer
local character = player.Character
local backpack = player.Backpack
local tool = backpack.Tool
collectionService:AddTag(tool, "test")
tool.AncestryChanged:Connect(function(_, newParent)
print(newParent, collectionService:HasTag(tool, "test"))
wait()
warn(newParent, collectionService:HasTag(tool, "test"))
end)
If you’re adding the tag from the client, and it looks like you are, the other clients will have no way of knowing the tool has a tag because of Roblox’s replication rules.
Out of curiosity I added a listener for CollectionService:GetInstanceRemovedSignal() to see if it was getting removed and it was.
Don’t know if this is the source of your problem but according to the documentation for GetInstanceRemovedSignal there are 2 conditions where the event is fired:
The tag is removed from an object within the DataModel (game) using CollectionService:RemoveTag (not the case for your scenario)
An object with the given tag is removed as a descendant of the DataModel , e.g. by un-setting Instance.Parent or similar
Not really to sure if this solution is suitable for your use case, apologies if it isn’t:
local collectionService = game:GetService("CollectionService")
local player = game.Players.LocalPlayer
local character = player.Character
local backpack = player.Backpack
local tool = backpack.Tool
collectionService:AddTag(tool, "test")
tool.AncestryChanged:Connect(function(_, newParent)
if tool.Parent.Name == "Backpack" and not collectionService:HasTag(tool, "test") then
collectionService:AddTag(tool, "test")
end
print(newParent, collectionService:HasTag(tool, "test"))
wait()
warn(newParent, collectionService:HasTag(tool, "test"))
end)
Thank you for the detailed explanation. I’m guessing this is a bug on Roblox’s end since both conditions are not met when the tag is being removed…
I will not mark your post as a solution because your solution is not very practical for me, but your reply was helpful because now I know it is probably not an issue only for me
When tags replicate, all tags on an object replicate at the same time . Therefore, if you set a tag on an object from the client then add/remove a different tag on the same object from the server, the client’s local tags on the object are overwritten.