Problems With Shooting on an authoritative Server

I am currently running a authoritative server using uLink’s middle ware. I am having issues with keeping the client and the server in sync when the player is shooting. Currently the player sends a RPC to the server, the server and client both create bullets. My issues is sometimes the server fires +/- one bullet from what the client does. Any suggestions on how to keep this more in sync. The code I am using is below.

This script is called every time we fire want to fire.
public void machineGunFire (){

        if (machinegunbulletsLeft == 0){
                return;
            }
         
            if (Time.time - mgfireRate > nextFireTime){
                nextFireTime = Time.time - Time.deltaTime;
            }

            while( nextFireTime < Time.time && machinegunbulletsLeft != 0){
                AmountofBulletsFired++;
                AmountofBulletsFiredForSpread++;
                StartCoroutine(machineGunOneShot());
                nextFireTime += mgfireRate;
            }
  

    }

On the server.

[RPC]
public void areWeFiringOurGun(bool varible, uLink.NetworkMessageInfo info){
        RPCSender = info.sender;
        weAreFiring = varible;
        TimeFireMessageWasSent = info.timestampInMillis;
        if(weAreFiring){
              machineGunFire();
        } 
 }
    
   

 void machineGunFire (){
            if (machinegunbulletsLeft == 0){
                //canWeFire = false;
                return;
            }
            if (Time.time - mgfireRate > nextFireTime){
                nextFireTime = Time.time - Time.deltaTime;
            }
            while( nextFireTime < Time.time && machinegunbulletsLeft != 0){
                machineGunOneShot();
                AmountofBulletsFiredForSpread++;
                nextFireTime += mgfireRate;
            }
        
        }

Are you sending the RPC as reliable? You need to compare your round trip time and then compare your shots per second. If the time between shots is less than your round trip time I’m not sure how you’ll fix it. If it is less then you can compare the delta time between the clients “pressed trigger” action, and “released trigger” action, and you should get the same amount of rounds.

The solution to your problem is depended on your game itself. If shooting in your game works similar to counter strike have a look at this:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

In my game the bullets move slow and have to be synchronized exactly between all clients thus I only send a request to shoot to the server and the server adds it to its world state on server side. The server sends this then 16 times per second to the clients. The client sees the shooting only after the signal comes back from the server. Thus if you shoot you won’t see immediately that something is happening.