Trouble with nullreferenceexception

Hello. I’m having trouble with this. I’m using instantiate to create enemies in a scene. On the enemy game object I have in the Awake() function

player = GameObject.FindWithTag(“Player”).transform.

When the player is defeated, the player object is destroyed. What happens next is I get a null reference exception from the enemies trying to find the player. How do I change it so that if the enemies can’t find the player, the enemy is destroyed and the null reference exception is avoided?

Thanks.

Thanks! Works great.