[PUN2[ Only one client changes value

Hello, I have a problem that only one client seems to affect a value in script. Here is the enemy script

float health;
    public void Update()
    {
        DisplayHealth();
    }
    public void DisplayHealth()
    {
        healthText.text = health.ToString();
    }
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(health);
        }
        else
        {
            this.health = (float)stream.ReceiveNext();
        }
    }

And here is the bullet script (bullet is instantiated by player and specific player is owner - I’ve read that only one player should check for collisions - that’s why there is this if(photonView.IsMine))

private void OnCollisionEnter2D(Collision2D collision)
    {
        if (!photonView.IsMine) return;
        if (collision.gameObject.tag == "Enemy")
        {
            collision.gameObject.GetComponent<EnemyController>().health -= 10;
        }
    }

When one player shoots enemy health updates on all clients. When another player shoots enemy then health changes and goes back to previous value.

I’d like to add that if I remove this from collision checking

if (!photonView.IsMine) return;

then the value syncs between all clients but is glitchy and jumps like crazy but after all it displays propper value

SOLVED: I’ve started using RPCs and it works like a dream but I still have no clue what I was doing wrong.

Guessing here: You tried to update the enemy’s health in OnCollisionEnter2D. However, the enemy is likely not under your control, so the other player’s client gets to send the health value. Meaning: Nobody can change “my” health directly. Anyone who wants to do that has to send an RPC to me, so I change it and send the new value.