Non-host clients will not call functions

I’m doing a grid-based TBS. I’m trying to spawn units and it’s working correctly on the host client, but not for the non-host.

There’s a Player class

public virtual void Update () {
        if (Input.GetKeyDown(KeyCode.J))
        {  
            Cmd_Spawn();
        }
    }

 [Command]
    public void Cmd_Spawn()
    {
        if (isLocalPlayer)
        {
            obj = (GameObject)Instantiate(GameManager.instance.InfantryPrefab, transform.position, Quaternion.identity);
            unit = obj.GetComponent<Infantry>();
            unit.gridPosition = new Vector2(transform.position.x + Mathf.Floor(GameManager.instance.mapSize / 2), -transform.position.z + Mathf.Floor(GameManager.instance.mapSize / 2));

            NetworkServer.Spawn(obj);
        }
    }

When the client tries to spawn, it’s showing “Trying to send command for object without authority.”

@KristophV
If this is your Player script I can see where it went wrong. Imagine you had two of these scripts running around and one of them is your player and the other one is some remote clients player. Now if you check if (Input.GetKeyDown(KeyCode.J)) what happens is that both of the scripts on the scene try to invoke your command when only your localPlayer should be invoking the command. You need to make sure that this is only ran from the local player by writing if(Input.GetKeyDown(KeyCode.J) && isLocalPlayer) for example.

Also, remove the isLocalPlayer checking from the Command. There is no way that will return true because commands are run on the server. The player object on the server is not your player object.

Hope this helps you.