Server Player can effect on client player but the client player can't effect

Hello … when i test my multiplayer game …but even when i make the Variables are replicated the Server player can effect on client player but the client can’t effect or damage the server player . please some one tell me exact thing that i have to do to fix this issue .

][1]

Variable replication only tells the server to update clients when a value changes. If a client changes a value, it will not be updated on the server.

You will need to create Server RPC functions that the client calls, that update the values you want. These will tell the server do the requested functionality.

yes man.I still need someone to explain the replication staff. I have Problem to understand it! :frowning: .

I believe Maide is correct, I’m adding an answer below (I went over the 2k character limit for a comment).

There are three types of RPC, which you can pick by clicking on a custom event node in your blueprint and changing the drop-down value for “Replicates.”

“Not Replicated” means that the event runs wherever it was called. If you call that event on the server, it runs on the server. If you call it on one of the clients, it runs on that client.

“Run on Server” means that the event will run on the server. This allows a client to send messages to the server.

“Run on Owning Client” means that the event will run on the client which “owns” the object you’re working with. Think about a PlayerController, for instance. If you’re on the server and call a “Run on Owning Client” RPC for that player controller, the client for that player will run the event. This only works from the server - I don’t think UE4 supports client-to-client communication, which is fine (you’re better off routing it through the server anyway).

“Multicast” runs on the server and all of the clients. Again, this only works from the server - calling it from a client (I believe) just runs it locally.

A word of caution - not all classes handle RPCs the same way. There’s a great reference here: Multiplayer Network Compendium | An Unreal Engine Blog by Cedric Neukirchen which might help.

In your case, you’re going to want “Run on Server.” Let’s assume the variable you want to update is your ammo for this example. First, you’d create a custom event in your PlayerController called - let’s call it “ServerUpdateAmmo.” Change that event’s replication type to “Run on Server” and check the “Reliable” checkbox (which tells UE4 that this is an important piece of information, not just a cosmetic thing that would be okay if it didn’t happen). From the execution pin of your “ServerUpdateAmmo” custom event, you’ll change the value of your replicated ammo variable. Finally, in the code where the player is shooting, you’ll call the “ServerUpdateAmmo” RPC instead of changing the ammo variable directly.

Basically, this allows your client to send a message to the server asking it to update the variable. Since it’s a replicated variable, the server can then push that out to all the clients. You could also use another custom event set to “Multicast” to update the clients (which sometimes helps if you need to do something more complex than setting a variable).

I’m also going to recommend logging along the way. It’s very useful for being able to see where an event is happening. For instance, it helped me realize that using RPC in the GameInstance class wasn’t working (this question: Why is the ServerTravel command not recognized for Dedicated Servers? - Blueprint - Epic Developer Community Forums).

Good luck!