Accessing other script variables error

I am trying to have a script check if a variable is not equal to 0 in another script. This the error I’m getting:

NullReferenceException: Object reference not set to an instance of an object
EnemyAI.Update () (at Assets/Scripts/EnemyAI.cs:20)

Code accessing other code:

void OnTriggerEnter2D(Collider2D col){
			if (col.gameObject.tag == "Bullet") {
				var move = gameObject.GetComponent<MoveTrail>();
				if(move.moveSpeed != 0){
					air = air - 10;
				}
			}
	}

Script MoveTrail’s moveSpeed is an int.

You neglected to say what line the error occurred on, but I assume it’s “if(move.moveSpeed != 0){”. That means the “move” variable is null, since evidently there is no MoveTrail component attached to gameObject. I’d recommend getting in the habit if checking whether variables are null before attempting to use them.