Stuck on replicating Ammo Count data

Hey everyone, I’ve managed to use the First Person Blueprint template to get a basic shooter running. So far I’ve managed to replicate the players projectiles dealing damage on both client and server. However, when it comes down to the ammo count, it only shows up on the server.

I have replicated my variables and I have set events to Multicast or Run on Server as well as making sure they are reliable.

I’ve also attempted to use the whole “Switch has Authority” switch but I still have issues.

My current setup displays the ammo count as 8 for each weapon (which is what I intended as the starting ammo). My issue now lies in the successful depletion of ammo when firing the weapon. On the server/host this works just fine. The client is unable to deplete the ammo and is unable to fire the weapon.

(below) When fire is called, it checks if the player has the appropriate weapon equipped, then proceeds to check the current ammo. Respectively triggering it to release a projectile if the criteria is met.

(below) Ammo is then supposed to be depleted by the value of 1 and then it will update the ammo of whatever weapon is selected

(below) This is where you cycle with the scroll wheel to choose the weapon you want to use.

(below) When the weapon is chosen, its ammo type is then loaded into a variable so that it can be depleted.

So there we have it in its current state, only firing and depleting ammo on the server/host side.

Screenshot 1: You don’t need to differentiate between server and clients here, just call “Server Fire” all the time. When called on a server, the server-RPC executes too (see the RPC table )

Screenshot 2: No need to execute the Deplete Ammo on every client, since the Ammo value is a replicated variable anyway. So just execute this on the server and every client should get this update. Also, I think you are trying to do a multicast call from the client, which is dropped. Only the server can do this (see RPC table).

It’s easy to get confused by replication, don’t feel bad about it :slight_smile: I think you confused RPC and replicated variables here and did way too much work.

I suggest you only do somethink like this:

  • the ammo counter is already replicated, so whenever the server changes it’s values, every remote version of this player gets updated anyway
  • Now, only do input handling locally and immediately call the server from here (Run on server).
  • The server then checks and depletes the ammo (which, thanks to variable replication, automatically is replicated back to everyone’s instance of this client’s pawn)
  • now the server fires the projectile. If you set this projectile to be a replicated actor, you don’t need to think about more replication at all, the projectile is then replicated to everyone!
  • if you don’t like this, you send a “execute on all” from the server and spawn a private,local projectile. You could actually totally ignore replication of the projectile and just destroy it on impact without doing anything, since…
  • damage handling should only be done on the server (by checking the authority in the OnHit event)
  • The only thing upon impact to execute on everyone’s computer is the animation, eg playing sound and animation

such a long question with nice screenshots but no response :frowning: