Damage from client to server

Hi, when I was working on the damage i’ve noticed that the client can’t deal damage to the server. Here’s my graph: Imgur: The magic of the Internet
What’s wrong with it? Thanks in advance.

The problem is that you are calling a multicast event that is being called from a client. Multicast events will only run on the client if called from a client. So the object you are passing to the server function most probably does not exist on the server. What I would advice you to do is:

  • On your attack function check if you are a client or the server. If you are a client call the server function, on server simply execute the code.
  • Run your ray traces on the server, not on the client and apply damage accordingly on server to replicate.
  • On your client simply run a simulation of the attack (particle effects, sounds, animations).

As a rule of thumb always remember that any RPC will run correctly only when called from the server. So anything you need to replicate do through a server call that then calls the corresponding RPC (in case of multicast or client), unless of course is a call to run on server.

Hope this helps as a guidance. If this info was useful please remember to mark it as the correct answer so other users can finde it easily. Make it a great day!

1 Like

How do I check if I’m the client or the server? And how do I properly apply the damage?

To check if you are on the server or on a client simply use the “Switch Has Authority” node. If it has authority is the server or the host player, otherwise is a client.

The way you are applying the damage seems correct at first glance. But it depends on your own game system. Just remember to remove the health on the server and not on the clients, since its a replicated variable. You can read all about it here: Networking Content Examples | Unreal Engine Documentation

something like this? Imgur: The magic of the Internet
(btw this doesn’t work, I’d just like to know if I’m on the right way)