So I have a script that tells me what the closest enemy is but how put the closest enemy into a gameObject variable?

here is my script

public float radius;
public LayerMask check;
public bool active = true;
GameObject enemy;

private void Update()
{
    if (active == true)
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, radius, check);
        Array.Sort(colliders, new EnemyDetector(transform));

        foreach(Collider item in colliders)
        {
            // I think the game object should go here.
        }
    }
}

private void OnDrawGizmos()
{
    Gizmos.DrawWireSphere(transform.position, radius);
}

}

https://forum.unity.com/threads/raycast-nearest-enemy.130189/
Try Raycasts. I made good expirience with them.

Since you sort you array, using an IComparer (EnemyDetector) I suppose, either the first or the last element of your array is the closest enemy you are looking for.

Collider[] colliders = Physics.OverlapSphere(transform.position, radius, check);
if( colliders.Length > 0 )
{
    Array.Sort(colliders, new EnemyDetector(transform));
    GameObject closestEnemy = colliders[0].gameObject ;
    Debug.Log( "The closest gameObject is : " + closestEnemy.name, closestEnemy ) ;
}