Enemy taking damage instead of the player?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class zombHit : MonoBehaviour
{
    public GameObject player;
    public float damage;
    private void OnTriggerStay(Collider other)
    {
        Debug.Log("Hitzone ENTERED!");
        if (other.gameObject == player)
        {
            GetComponentInParent<NavMeshAgent>().speed = 0;
            GetComponentInParent<Animator>().Play("Attack");
        }

    }
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject == player)
        {
            GetComponentInParent<NavMeshAgent>().speed = GetComponentInParent<EnemyAI>().chasemoveSpeed;
           
        }
    }

    private void takeDamage()
    {
        player.GetComponentInParent<Target>().TakeDamage(damage);

    }
  
}

So, I was recommended to using Animation events where when the animation plays it would activate the function take damage. However, instead of the enemy doing damage to the player it is damaging itself. I’m pretty new to using animation event so I’m clueless here despite accessing the players health script that I named “target” for it to do damage to. Moreover, it does not accept the variable given as the damage which I in the inspector had to set it in the animation event bar as a float.

We’ll need to see the Target script, the issue is most likely there.

Animation events invoke a function on the object that has the Animator attached to it, if I understand them correctly. From your other thread you said it was the enemy doing the attack Animation right?

using UnityEngine;

public class Target : MonoBehaviour
{
    public float health = 100f;
    public void TakeDamage (float amount)
    {
        health -= amount;
        if (health <= 0f)
        {
            Die();
        }
    }
    void Die()
    {
        Destroy(gameObject);
    }


}

This is the target script.

Yes, its the enemy doing the attack animation.