make enemy stop at distance and play animation

I want to keep the enemy above ground script.I like how it works.I want to add the STOP script to it.Combining the 2 scripts isn’t an easy task for me.I get error after error.

enemy above ground script first

var LookAtTarget:Transform;
var speed : float = 3;  
var controller:CharacterController;
    
function Start()
{   
    animation.Play("idle 1000");
    controller = gameObject.GetComponent(CharacterController);
}
    
function Update()
{    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	transform.LookAt(Vector3(LookAtTarget.position.x, transform.position.y, LookAtTarget.position.z));  
        
    controller.SimpleMove(speed*transform.forward);
    animation.Play("walk 1000"); //You play the animation
}

here is the Stop script

var target : Transform;
var moveSpeed = 0;
var rotationSpeed = 3;
var player : Transform;
var distance:float = 5.8;
var distanceAttack:float = 2.6;
var myTransform : Transform;

function Awake() {

    myTransform = transform;
}
 
function Start() {

    animation.Play("idle 1000");
    target = GameObject.FindWithTag("Player").transform;
}
 
function Update () {
    if(Vector3.Distance(transform.position, player.position) < distance){
        if(Vector3.Distance(transform.position, player.position) >distanceAttack){
        moveSpeed = 5;
        animation.Play("walk 1000");
        myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
        myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
    }

I added this snippet

transform.LookAt(Vector3(LookAtTarget.position.x, transform.position.y, LookAtTarget.position.z));

into the above ground script.this helped with the player following the terrain on the y axis.

i cant seem to get enemy to follow me on y axis and stop at distance to play the animation that works in the STOP script.

HI
I have answered a similar question Here