Need help understanding ClientRpc from Unity Networking tutorial,Question about clientrpc

Hello,
I am going through the Unity networking tutorial and wondering if someone could explain how the ClientRPC function works in the code below?
From what I understand when a player object takes damage, on the server the player object’s health is reduced. When the health is <= 0, then the server executes the RpcRespawn function on all the clients. The part that confuses me is the " if(isLocalPlayer) " part. On every client’s computer who is playing this game, wouldn’t this function execute and because each client’s player object is the local player on their computer, the why doesn’t each client’s local player object move to Vector.zero?

Source is here:

https://unity3d.com/learn/tutorials/topics/multiplayer-networking/death-and-respawning?playlist=29690

public void TakeDamage(int amount)
    {
        if (!isServer)
            return;
        
        currentHealth -= amount;
        if (currentHealth <= 0)
        {
            currentHealth = maxHealth;

            // called on the Server, but invoked on the Clients
            RpcRespawn();
        }
    }

 [ClientRpc]
    void RpcRespawn()
    {
        if (isLocalPlayer)
        {
            // move back to zero location
            transform.position = Vector3.zero;
        }
    }

Thanks in advance.

isLocalPlayer makes sure the code is only run if you are the version that is on the computer. Everyone is running copies of the same code, so isLocalPlayer allows you to say that you only run the code in the right situation.

Hi, so if you have 2 human players playing on two separate computers, then doesn’t RpcRespawn() run on both computers? If so, then what is stopping both human players from returning true when running the code if( isLocalPlayer) part?

@spidermancy612

Hi @Bunny83,

When clientRPC is called, I thought it is called on all the clients. So client 1 is PC1 and client 2 is PC2. So when clientRPC is called the RpcRespawn() function will run on PC1 player 1’s object (or A) and PC1 player 2’s object (or B). Since PC1 player 1’s object will return true when running 'isLocalPlayer", this object is moved to (0,0,0). The NetworkTransform would move Player 1’s object (A) on PC2 to (0,0,0) as well.
At the same time, since PC2 is a client, player 2’s object (B) will return true when running ‘isLocalPlayer’ and move this object to (0,0,0). Then network transform would move this object on PC1 to (0,0,0). In the end both objects end up at (0,0,0). I know this is wrong from watching the tutorials on youtube, but can you explain where I go wrong in my thinking?

Thanks.