Multiplayer melee game - client cannot deal damage

Hello guys!
I made a simple 3d game using the unity UNET. The problem i am having is that when i join the host as client the client can’t deal damage. Help me fix this, please.

void OnTriggerEnter(Collider col)
    {
        if (isAttacking && alreadyAttacked == false && col.gameObject.tag=="Enemy")
        {
            alreadyAttacked = true;
            if (SceneManager.GetActiveScene().name == "Arena")
            {
                col.gameObject.GetComponent<Health>().TakeDamage(damage);

            }
        }
         
    }

This code gets called when the sword’s box collider enters the enemy’s collider and sends the damage to the enemy’s script.

enemy script:

public const float maxHealth = 100;
    [SyncVar(hook ="OnChangeHealth")] public float currentHealth = maxHealth;
    public RectTransform healthbar;

    public void TakeDamage(float amount)
    {
        if(!isServer)
        {
            return;
        }

        currentHealth -= amount;
        if(currentHealth<=0)
        {
            Destroy(this.gameObject);
        }

    }

    void OnChangeHealth(float currentHealth)
    {
        healthbar.sizeDelta = new Vector2(currentHealth * 2, healthbar.sizeDelta.y);
    }

So your TakeDamage method is set up to only work on the server. OnTriggerEnter first checks if isAttacking is true before checking a few other things and ultimately calling TakeDamage. Are you setting isAttacking to true on the server, or the client? Because as written it will only ever apply damage if isAttacking is true on the server. You haven’t posted where the value of isAttacking comes from, and if/how you send this value from the client to the server so OnTriggerEnter works correctly.

Also Unet is deprecated. I’d recommend switching to a 3rd party network API before you invest too much in dead Unet.