Spawning object at wrong location

Hi, I’m trying to have an object be spawned where the player is looking at on a key press. When the host presses the spawn key, everything works fine. The clients on the other hand have their objects spawned at coordinates (0,0,0) instead of where the player is looking at. Here is the code:

public class PlaceGuard : NetworkBehaviour
{

    private Camera MainCamera;
    private int layerMask = 1 << 8;
    public GameObject TrapPrefab;
    [SyncVar]
    private Vector3 HitLocation;


    void Start()
    {
        MainCamera = GetComponentInChildren<Camera>();
    }

    void Update()
    {
            CastRay();   
    }
    void CastRay()
    {
        //Spawning BearTrap
        if (Input.GetKeyDown(KeyCode.T))
        {
            Ray ray = MainCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray.origin, ray.direction, out hit, 3.0F, layerMask))
            {
                HitLocation = hit.point;
                CmdSpawnTrap();
            }
        }
    }
    [Command]
    void CmdSpawnTrap()
    {
        GameObject Trap = (GameObject)Instantiate(TrapPrefab, HitLocation, Quaternion.identity);
        NetworkServer.SpawnWithClientAuthority(Trap, connectionToClient);
    }
}

I’d appreciate any help.

I think you have to use Network.instantiate (Network.Instantatiate)
As far as I know, this syncs its position with other ones. Also make sure you have an RPC attached to the trap (at least that is how it works with photon)

After alot of tial and error I finally found my mistake, I’ll post the answer if someone encounters the same problem:

The solution was to add the Vector3 HitLocation variable as a parameter of the CmdSpawnTrap funtion.