How to sync two health bars (Sliders) of two different players on network (Netcode)

I am trying to make a 2v2 multiplayer combat game, It contains two health bars, one for each. The problem is the health system works perfectly fine on the host side but the health bars(sliders) are not changing their value on the client side but the network variables are updating on both sides. I am using Unity’s Netcode.

public class HealthBar: NetworkBehaviour
{
	public static HealthBar instance;
	public Slider slider;
	public Gradient gradient;	
	public Image fill;
    private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}
	public void SetMaxHealth(NetworkVariable<int> networkedHealth)
	{
		if (!IsServer) return;	
		slider.maxValue = networkedHealth.Value;
		slider.value = networkedHealth.Value;
		fill.color = gradient.Evaluate(1f);	
	}
	public void SetHealth(NetworkVariable<int> networkedHealth)
	{
		if (!IsServer) return;     
		slider.value = networkedHealth.Value;
		fill.color = gradient.Evaluate(slider.normalizedValue);
	}
}

Hi did you ever figure this out? Running into the same issue

Hello! I had a similar problem. My client UI (health bar) didn’t update but on my host it updates correctly.
What have I done?

Just added

 [ClientRpc]
    public void TakeDamageClientRpc(int damage)
    {
       
        damage -= armor.GetValue();
        damage = Mathf.Clamp(damage, 0, int.MaxValue);
        currentHealth -= damage;
        this.healthBar.SetAmount(new NetworkVariable<int>(currentHealth));
    
        Debug.Log(transform.name + " takes " + damage + " damage. Has now " + currentHealth + " HP");
        if (currentHealth <= 0)
        {
            Die();
        }
          
       
    }

Hope this soultion will work for You to! :wink: