[Solved] How to check for the nearest gameobject within a trigger?

I have a (probably) extremely simple question. Any help is welcome! I have an empty game object (called holdpoint) with a large trigger collider component that acts as a hitbox to pick up items. The following script is used to pick up items:

void OnTriggerStay(Collider other)
{

    if (Input.GetButtonDown("Fire"))    //If mouse is clicked
    {
      
        if (other.gameObject.tag == "Object")   //If gameobject that is colliding with the collider has the correct tag
        {
            GameObject item = other.gameObject; //reference to that gameobject
            if (isHolding == false) 
            {
                item.GetComponent<Rigidbody>().isKinematic = true;  //freeze rigidbody
                item.transform.position = transform.position;   //move gameobject to holdpoint
                item.transform.parent = gameObject.transform;   //set gameobject's parent to holdpoint

                isHolding = true;
            }
            else
            {
                item.GetComponent<Rigidbody>().isKinematic = false; //unfreeze rigidbody
                item.transform.parent = null;   //set gameobject's parent to none

                isHolding = false;
            }
        }
        
    }
}

This script works well enough, except when objects of the same tag overlap. The issue is with:

            GameObject item = other.gameObject; //reference to that gameobject

It checks the hierarchy for the first object with the relevant tag. How can I make a reference to the nearest gameobject within the trigger, rather than the first one listed in the hierarchy? Thanks for any suggestions/feedback!

CODE NOT TESTED

private const string PickableObjectTag = "Object";
private HashSet<Collider> _objectsInTrigger = new HashSet<Collider>();
private GameObject _heldObject = null;
// Delete isHolding variable

private bool IsHoldingObject => _heldObject != null;

void Update()
{
    if (Input.GetButtonDown("Fire"))
    {
        if(IsHoldingObject)
        {
            DropHeldObject();
        }
        else
        {
            GameObject closestObject = GetClosestObjectInTrigger();
            if (closestObject != null)
            {
                PickObject(closestObject);
            }
        }
    }
}

void DropHeldObject()
{
    _heldObject.GetComponent<Rigidbody>().isKinematic = false;
    _heldObject.transform.parent = null;
    _heldObject = null;
}

void PickObject(GameObject target)
{
    target.GetComponent<Rigidbody>().isKinematic = true;
    target.transform.position = transform.position;
    target.transform.parent = transform;
    _heldObject = target;
}

GameObject GetClosestObjectInTrigger()
{
    GameObject closestObject = null;
    float closestDistanceSqr = Mathf.Infinity;
    Vector3 currentPosition = transform.position;
    foreach(Collider objectInTrigger in _objectsInTrigger)
    {
        float sqrDistanceToObject = (objectInTrigger.transform.position - currentPosition).sqrMagnitude;
        if(sqrDistanceToObject < closestDistanceSqr)
        {
            closestDistanceSqr = sqrDistanceToObject;
            closestObject = objectInTrigger.gameObject;
        }
    }
 
    return closestObject;
}

void OnTriggerEnter(Collider other)
{
    if(other.CompareTag(PickableObjectTag))
        _objectsInTriggeer.Add(other);
}

void OnTriggerExit(Collider other)
{
    if(other.CompareTag(PickableObjectTag))
        _objectsInTriggeer.Remove(other);
}

@Hellium Thank you! That works perfectly!