StarterCharacterScripts - Script vs. LocalScript

For scripts in StarterCharacterScripts, how do I know whether to use a Script vs. a LocalScript? For example, the following code works in a Script but not in a LocalScript:

game:GetService("CollectionService"):AddTag(script.Parent, "ZombieFriend")

Obviously the Roblox documentation indicated using a Script. And I’ve read a bunch of answers from searching on Google. But I still can’t tell just by looking at the code that this wouldn’t work in a LocalScript. What am I not understanding? (I’ve only been scripting Roblox for about two months now, so I’m still getting up-to-speed.)

1 Like

Are you trying to detect if it has the tag from the server? Since it is a local, the changes it makes are not seen by the server and I assume that the replication of CollectionService is within that.

2 Likes

From what I know, localscripts are client-side and scripts can be told what to do on either client or sever

1 Like

For a lot of things the only way to know if you can use something on client/server is by testing or looking up documentation → Roblox Creator Documentation
But the general idea is that something like game.Players.Localplayer needs the client to figure out WHO is the localplayer. I think most of the restrictions for client server are based on access to specific data or a function.

1 Like

How are you determining if it works or not?

Does one error and not the other?
Does it just not function properly?
If it doesnt function properly you’re probably trying to set the tag on the client and access it on the server
Almost anything done in a local script cannot be seen by server scripts

2 Likes

I’m just using the tagging as defined by the Roblox NPC Kit:

1 Like

Putting the code in a LocalScript does NOT produce any errors. It just fails to take effect and the NPC Zombies attack my character. Putting the code in a Script, however, works as expected.

Use a server script for the reason I gave, client tags are only visible to that player.

2 Likes