Not asigned health script

I am having a small problem which I don’t understand.

I am importing health script corectly in my EnemyAI but when it’s about taking damage I get the error that the component is not asigned.

    public HealthBarGUI health;
	void Awake(){
		myTransform = transform;
		controller = GetComponent<CharacterController>();
		health = GetComponent<HealthBarGUI>();
		currentWaypoint = WayPoint1;
    void Attack (){
	if( attackDelay == 0 )
			attackDelay ++;
		health.curHealth = health.curHealth - maxDamage;
	if( attackDelay	> 3)
			attackDelay = 0;

And the error I get is the following :

“Object reference not set to an instance of an object on line health.curHealth”

I just found out that without this declaration

health = GetComponent<HealthBarGUI>();

it will work just fine but you have to attach the script by yourself.