Rpc call only being called on host

I’m creating a simple LAN multiplayer game where one player is server and the other one is client. I’m trying to inform player_1 that he killed player_2 (or that player_2 killed player_1). I wrote this code but it doesn’t work. It displays text on server (host player). For example if player_1 (client) kills player_2 (host), then the text will be displayed on hosts screen (instead of clients) saying “You killed player_2”, and if host (player_2) kills client the same will happen, it will say “You killed player_2”.

Here’s function that’s being called when a player needs to take damage.

public void TakeDamage(float amount, NetworkInstanceId NetID){
        if(isServer){
            m_Health-=amount;

            if(m_Health<0.1f){
                RpcOnDeath(NetID);
                m_Health = 100f;
            }
        }
    }

NetID is network identity of the shooter and it’s being passed to take TakeDamage and then to RpcOnDeath function.

Since I want to tell player_1 that he killed player_2 I try to send a message like this:

[ClientRpc]
    void RpcOnDeath(NetworkInstanceId ID){
/*
             Respawn code...
*/
            // Find game object on server with this ID and run function
            GameObject Killer = NetworkServer.FindLocalObject (ID);
            PlayerHealth KillerHealth = Killer.GetComponent<PlayerHealth>();
            KillerHealth.KillNotification (MyNickname);
       
    }

And KillNotification is a simple function that only displays text to killer like this:

public void KillNotification (string Killname){
        KillConfirmation.GetComponent<Text> ().text = "YOU KILLED " + Killname;
        KillConfirmation.GetComponent<Text>().enabled = true;
    }

I can’t figure out what’s wrong. :frowning:

NetworkServer.FindLocalObject () won’t work on clients (except for a host). Try ClientScene.FindLocalObject() instead.

Take a look at the NetworkIdentity.observers in the editor. If for some reason the object isn’t being observed then the RPC wont be sent/received.

I changed my RpcOnDeath to this:

GameObject Killer = ClientScene.FindLocalObject (ID);
PlayerHealth KillerHealth = Killer.GetComponent<PlayerHealth> ();
KillerHealth.KillNotification (MyNickname);

And KillNotification to this:

public void KillNotification (string Killname){
        if (isLocalPlayer) {
            KillConfirmation.GetComponent<Text> ().text = "YOU KILLED " + Killname;
            KillConfirmation.GetComponent<Text> ().enabled = true;
        }
    }

And this is how I get player name:

void Start(){
        if (isLocalPlayer) {
            MyNickname = PlayerPrefs.GetString ("PlayerNickname");
            MyNickname = (MyNickname.Length <= 0) ? MyNickname = "NO NICKNAME" : MyNickname = PlayerPrefs.GetString ("PlayerNickname");
        }
    }

If I call KillerHealth.KillNotification (“Example name”) in RpcOnDeath it will work as intended. But the code above doesn’t. If player_1 kills player_2 then it will show notification to player_1 with following message “You killed player_1” (it should be “You killed player_2”), and if player_2 kills player_1 it will show notification to player_2 with this message “You killed player_2” (it should be “You killed player_1”).

It all works fine except names.