how to turn enemy AI off

var AwareDistance = 10;

var Enemy : Transform;
var Player : Transform;

function Start () {
    GetComponent("EnemyAI").enabled = false;
}

function Update (){

    //Attack
    if(Enemy.position.x - Player.position.x < AwareDistance)
        GetComponent("EnemyAI").enabled = true;
    else 
        GetComponent("EnemyAI").enabled = false;

    //z
    if(Enemy.position.z - Player.position.z < AwareDistance)
        GetComponent("EnemyAI").enabled = true;
    else 
        GetComponent("EnemyAI").enabled = false;

}

My AI runs from another script but i want to turn it off with this one when the player is a certain distance away, however it doesn't work am i doing it wrong?

First of all, position.x is simply the position on the X-Axis (whether or not they are close to each other on that axis), so you could be a mile away from the enemy on the Z-axis and your function not trigger if your x positions are similar.

Also, where are these scripts? If this script is on the player and the EnemyAI script is on the enemy unit, then this won't work because the EnemyAI script isn't a component of the player object. Try:

On the enemy in a script called EnemyAI:

var isRunning: boolean = false;

function DisableAI(){
    isRunning = false;
}

function EnableAI(){
    isRunning = true;
}

function Update(){
    if (isRunning){
        // put your AI scripting here
    }
}

On the player (or in your "helper") script (assuming you still cache the enemy gameobject under Enemy) under the Update():

if (Vector3.Distance(Enemy.transform.position,Player.transform.position) > awareDistance){
    Enemy.DisableAI();
}
else{
    Enemy.EnableAI();
}

This is not the best way to do it, since you are checking every update to decide whether the AI should be on (ideally, you should only call the AI off/on functions when the situation changes), but it should get you started.