CollectionService is Client/Server specific?

From what I read in the API services and numerous prior discussions, CollectionService is a way for clients to pass information to the server without calling events. This is desirable, as I’m trying to create an aggro function that constantly checks whether the monsters can see and chase the player. “Player D just went into room 50 from room 48? Stop checking room 48, start checking room 50.” That was the plan.

I’m already tracking the players for movement, so the client is the best place to check for this stuff.

So, the client talks to server? Obviously, this is not true:

  1. “PLAYER” is the tag (PlayerTag), added when PlayerAdded is called. I immediately use GetTags to make sure it is there. Note “Client”

Code:
localPlayer.CharacterAdded:Connect(function(character)
CollectionService:AddTag(character, PlayerTag)
print(CollectionService:GetTags(character))
end)

  1. “0” is the size of the table of PLAYER tagged items on the server, monitored by heartbeat.

Code:
tagtable = CollectionService:GetTagged(“PLAYER”)
print(#tagtable)

Am I wrong, or do I need to be calling CollectionService from the server at all times? I don’t feel like any line of code did anything but what I asked it to do. I have a second tag performing identically.

The only other explanation I can think of is that GetTagged is not updating unless I call an event. It’s possible, but it’s also the more complicated explanation.

1 Like

The API says this about replication

Replication

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. In StreamingEnabled places, instances can be unloaded as they leave the client’s streamed area. If such an instance re-enters the streamed area, properties and tags will be re-synchronized from the server. This can cause changes made by LocalScript s to be overwritten/removed.

What this means is when the server adds a tag, all of the tags for that Instance are replicated, and any tags that the client added are overriden.
Tags do NOT replicate from client to server

I read that differently, but it didn’t line up with results.

So… always call AddTag from server. I can do that. I will always be monitoring from the server, occasionally updating from the client.