Passing Variables to another script

I’m trying to pass a variable from my HealthScript to my AI attackscript but I get nullreferenceexception errors. I’m not sure of how to pass it, can anyone check my scripts?

AI AttackScript

using UnityEngine;
using System.Collections;
 
public class AttackScript : MonoBehaviour {
 
    Transform player;
    Transform _transform;
    float sqrRange = 3;
	AIScript AIscript;
    public GUIStyle customGuiStyle;
	
	//Temp HP
	float HP = 100f;
	
	//Accessing HP script
	HealthScript HPscript;
	
   void Start(){
	  HPscript = GetComponent<HealthScript>();
	  AIscript = GetComponent<AIScript>();
      player = GameObject.FindGameObjectWithTag("Player").transform;
		
      if (player == null)
          Debug.LogError("No player on scene");
      _transform = GetComponent<Transform>();
   }
 	
	void AttackColliision(){
		Vector3 direction = player.position - _transform.position;
		if(AIscript.animation.IsPlaying("G_AttackScript") && (direction.sqrMagnitude < sqrRange)){
			 if(Vector3.Dot (direction.normalized,_transform.forward) > 0){
				//Damage Script
				 	HPscript.HP -= 50;
				if(HPscript.HP <= 0){ Time.timeScale = 0; AudioListener.pause = true;
				 print(HPscript.HP);	
			  }
			}
		}
	}
	
	void Update(){
		Debug.Log(HPscript.HP);
		if (HPscript.HP < HPscript.maxHP) HPscript.HP += HPscript.healSpeed * Time.deltaTime;
	}
	
	void OnGUI(){
		GUI.Box (new Rect (Screen.width - 125,10,100,20), "Health: " + HPscript.HP, customGuiStyle);
		if(HPscript.HP <= 0){
			GUI.Box (new Rect (Screen.width / 2,Screen.height / 2,100,50), "You are Dead!", customGuiStyle);
		}
	}
}

My HealthScript
using UnityEngine;
using System.Collections;

public class HealthScript : MonoBehaviour {
	public float HP = 100f;
	public float maxHP = 100f;
	public float healSpeed = 5f;
	
}

You will need to change your variable declaration to be public like:

public HealthScript HPscript;

Then, in the editor, simply drag the object that has the script on it over to the variable propertie in the inspector view.

Now, if the scripts are on prefabs that are instantiated, you obviously won’t be able to drag and drop them in the editor (they won’t exist yet). Instead, you will need to find the objects and then get the components. This SHOULD happen in the start method (assuming they have been instantiated before that):

HPScript = GameObject.Find("Name of Object").GetComponent<HealthScript>();

Do the same for the AI script (if needed).