Null essentially means "has not been assigned to anything". And you can't access any field or functions on something that is null, or you'll get an error and your script will exit.
In your case, `FindClosestEnemy()` is returning null when there are no enemies in range. So when you try to access the `transform` field, the script is failing.
If there is a possibility that something will return null, you need to include a null check before using it. In this case:
closestEnemy = FindClosestEnemy();
if (closestEnemy != null)
{
// Put all code that depends on the enemy here.
// Don't use closestEnemy outside this block.
target = closestEnemy.transform;
// More stuff.
}