Enemy tracking

I am having trouble getting my enemy to move towards the player as of right now it moves away what do I need to change in order to fix it?

public class enemy : MonoBehaviour
{
    Transform playerTransform;
    UnityEngine.AI.NavMeshAgent myNavmesh;
    public float checkRate = 0.001f;
    float nextCheck;
   
    // Start is called before the first frame update
    void Start()
    {
        if (GameObject.FindGameObjectWithTag("Player").activeInHierarchy)
            playerTransform = GameObject.FindGameObjectWithTag("Player").transform;

        myNavmesh = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
    }
   
    // Update is called once per frame
    void Update()
    {
       if (Time.time > nextCheck)
        {
            nextCheck = Time.time + checkRate;
            FollowPlayer();
        }
    }
    void FollowPlayer()
    {
        myNavmesh.transform.LookAt(playerTransform);
        myNavmesh.destination = playerTransform.position;
    }

}

you should probably use myNavmesh.SetDestination() instead of myNavmesh.destination =, and maybe the rotation makes him move in the wrong direction, so put the following code in your Start() method:
myNavmesh.updateRotation = false;

I changed the code like you suggested put I’m still having trouble getting it to work could it have something to do with the asset that I am using which is tagged as player?

Depends on the Asset … Outcomment the following lines in your Start function

if (GameObject.FindGameObjectWithTag("Player").activeInHierarchy)
            playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
        myNavmesh = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();

make the variables “playerTransform” and “myNavmesh” visible in the inspector by making them public or adding the [SerializeField] attribute, then assign them manually.
You can assign an Empty GameObject instead of the PlayerTransform to check the behaviour - also check if the navmesh is generated correctly, re-bake it maybe.