Where to store a remote event for a character

So I’m trying to change the texture of a hat whenever a player changes teams. I have a local character script that fires a remote event whenever the team changes. A server script in the character would then change the texture of the hat. However, I can’t figure out a good place to store the event so that it’s only tied to that player.

I can’t put a script in the accessory because I guess scripts don’t run in accessories.

Is there a safe place for the event?

Personally, I would store my remotes in ReplicatedStorage since both the client and server can access it.

Also instead of having a server script in every single players character, I would have one script in ServerScriptService that listens for the remote event in ReplicatedStorage. Once fired, the script will get the Players character (this is easy as the Player that fired the remote is always passed as an argument with .OnServerEvent) and simply do whatever I need to.

1 Like

What i do, is put a local script, a remote event inside the local script then the server script inside the remote event. then in the server script, i would use script.Parent.OnServerEvent, because that means that the script will only react to its parent, and other local scripts cant interact with that script , since its not a descendant of it

I use the same system as @Ze_tsu. Put the Remote Event in the Replicated storage and a Script in the ServerScriptService. From within the script you can do something like this:

local RS = game:GetService("ReplicatedStorage")

local remoteEventName = RS:WaitForChild("RemoteEventName", 1)

if remoteEventName then
    remoteEventName.OnServerEvent:Connect(function(player)
        --The player parameter is the player who fired the event from their client
    end)
end
1 Like