How can i get this code to run only on the client that calls it?

Im trying to make it so that when a player changes their camera perspective from third or first person the location of the item in their hands attaches to the correct socket, but only for that player. (i have third person and first person character models)

Its already working here where when a player initially equips an item:

for some reason the code here wolnt work whey i try to change perspectives, if a client changes perspective it works, only changes item location for that client, but when the server player does it, it changes for everyone:

If server player is changing a networked variable, it will be changed on all clients. Look for this. FirstPersonItem is a networked variable and used here. I’m not sure the context, but I’d look at the implementation of that first.

Not exactly sure what you mean sorry, I know that somehow its getting called through the server, i just checked all these variables and none are replicated though, here is my full code for this:

On my player character:

On my inventory component:

FirstPersonItem variable in your second screenshot in your first post is replicated. Do a right-click on that variable, search for references by name all, look at where it is modified.

after this review I would ask: why is this affecting all clients? does it actually need to be replicated? if so can it’s state be derived from already replicated vars?

ok i see, the images in the first post arnt correct anymore, the second post has the current code. I believe the issue lies with “First Person?” bool variable, i think for some reason its replicating, even though replication is set to none

Ok after further testing it is indeed this variable, when it gets passed into this function on my inventory component for some reason its causing replication, when i tested without that variable, my code worked right.

What could be causing that variable to become replicated? is it because my component is replicated or something else?

gotcha. in your second post i dont see anything that would run over the network. I don’t think AttachActorToComponent does any networking itself but maybe it’s making your equipped actor kind of network the attachment over. If you are networking your equipped actor’s position/location it may be causing this.

I usually base my equip-able items on UObject rather than AActors, so I don’t run into this. Actors as inventory items may be something to reconsider.

I might use Objects with attributes, ie static_mesh, weapon_damage, weapon_thumbnail, etc. Then use that object data to spawn components to attach. For a droppable pickup, create a ‘DroppedItem’ BP actor with a static mesh component and use the same UObject to populate the mesh there, so you don’t have to create BP actors for every object in your game.