Where's the best place to store localscript that runs for every Character?

I don’t just mean your own character (ie, Player running their own character code) I mean every character in every instance of the game.

I want to make changes to each character based on their location and things around them. Things like attaching lights and particle emitters. All the information I need for this is in the workspace, so I want to avoid relying on server scripts.

For example, I can deal with my own avatar by sticking some code in StarterCharacterScripts or StarterPlayerScripts, but that would would only apply to my character. If that script added a model of a light bulb above my head, I would see it, but you wouldn’t; you would see the lightbulb above your head but not mine. I’d want to see both lightbulbs.

You would have to adapt your code to run on the server. The safest spots for server scripts are ServerStorage or ServerScriptService. And you would just need to rely on the Players service to get all of the players currently in the server.

The server needs to handle adding the lightbulbs so that it gets replicated to all clients.

That’s what I’m trying to avoid. Running the script on the server means have to send messages to each client. I have the information I need locally, but don’t know a good design pattern for dealing with it there.

If all you are doing is adding a light bulb model on top of the player you don’t need any client side code. The server can do that without issue.

Thanks for your help, but this isn’t what I’m looking for.

I know how to do it from the server. I’m trying to not.

Ah, okay. Well, some part of your code will need to be on the server. You can use RemoteEvents from the client to server. Which can then send information to all other clients.

1 Like

All the information I need is local. I’m not saying there’s a good solution for doing it entirely with localscripts and I may not choose to do it this way, but I’m not looking for any help solving this with server code. That’s not what this thread is for. It’s not what I asked.

StarterCharacterScripts is my priority way. It’s nearly impossible to stay safe against exploiters with local scripts though.

The problem is that there is no way to share information between clients without first going through the server. You can just get the information you need from a client, send it to the server, and send that information to all other clients.

1 Like

I don’t need to send any additional information from one client to another. Everything I need is in the workspace.

Perhaps I’m not explaining myself well. Maybe an example would help -

Suppose I wanted everyone who’s character.Name started with a vowel, to emit light from their right foot. Every client has the information they need to do that. There’s no reason that needs to run on the server, and no reason from one client to send information to another.

I’m not really worried about the code being exploited because their won’t be any game logic in it. It’s just for updating visuals.

How would you use StarterCharacterScripts to apply to all characters? I know you could get reference to all other characters, but it feels messy to have code on one character handling logic for them all.

You would need to do a Server Script, iterate through all of the players, and see if their name starts with a vowel.

Example:

for i,v in pairs(game.Players:GetChildren())do
     local newName = v.Name.lower()
     if newName "^a" or newName"^e" or newName "^i" or newName "^o" or newName "^u" then
        etc....
    end
end

I’m not really looking for players starting with a vowel.

I’m sorry; I don’t think you’re able to help.

All the information you need being in Workspace is irrelevant to your issue.

You need to use a server script for this no matter how you do it, whether that be by remotes or letting the server script do all of the work.

Put a local script into StarterPlayer>StarterCharacterScripts

The script will be put into the character every time it loads, and will get destroyed when the character respawns. You can reference the humanoid by doing:

local human = script.Parent:WaitForChild(“Humanoid”)

That’s what I said and he didn’t listen smh

I don’t understand what he is asking then

I’ve solved it. I’ve put a localscript in ReplicateFirst that keeps state for each player.