Using for loop to gather all waypoint objects near player

I’m having a problem with a list that I’m creating for all waypoints near the player. The total number of teleporters in the first list is 7, but the second list prints higher than that and eventually the index goes out of range. I’ve been at this for a few hours trying to figure out what is going wrong, but I’m drawing a blank.

Any ideas? I’d greatly appreciate any assistance.

//Filling the teleporter list

Teleporters = GameObject.FindGameObjectsWithTag("Teleporter");
        NumberOfTeleporters = Teleporters.Length;

//in a Get Button Down if statement
 if (!Finding)
            {
                FindNear();
                Finding = true;
            }

//This is the function that is supposed to gather all teleporter waypoints and add the waypoints within distance parameters into a new list. It then sets a child object on

 void FindNear()
    {
        for (int i = 0; i < NumberOfTeleporters; i++)
        {
            if (Vector3.Distance(CameraRig.transform.position, Teleporters*.transform.position) < MaxRange &&*

Vector3.Distance(CameraRig.transform.position, Teleporters*.transform.position) > MinRange)*
{
NearTeleporters.Add(Teleporters*);*
NearTeleporters*.GetComponent().Portal.SetActive(true);*
}
}
NumberOfNear = NearTeleporters.Count;

Clearing = false;
}

//In a get button up if statement
if (!Clearing)
{
NearClear();
Clearing = true;
}
//Function that clears the second list and sets all child objects in that list as inactive

void NearClear()
{
if (NearTeleporters[0] != null)
{
for (int i = 0; i < NearTeleporters.Count; i++)
{
NearTeleporters*.GetComponent().Portal.SetActive(false);*
}
NearTeleporters = new List();

NumberOfNear = NearTeleporters.Count;

}

Finding = false;
}

@Scribe is right
lets say that you add to the NearTeleporters.Add(Teleporters*); for indexes i = 0 , i =5 , and i = 6;*
for the second index i = 5 you’re trying to access the 5th element of NearTeleporters when it only has 2 elements at that point and it throws an error
NearTeleporters*.GetComponent().Portal.SetActive(true); cant be executed*

You can try it like this this will alow you to find the smallest distance, also read something on Mathf and Vectors

        using System;

        GameObject[] yourObjectsArray = new GameObject[0] ; // Asign it first somwhere
        Vector3[] ObjectsCoordinates = new Vector3[0];
        float[] closestArr = new float[0];
        for (int i = 0; i < yourObjectsArray.Length; i++)
        {
            GameObject obj = yourObjectsArray*;* 

ObjectsCoordinates = new Vector3(obj.transform.position.x, obj.transform.position.y, obj.transform.position.z);
closestArr = Vector3.Distance(transform.position, ObjectsCoordinates*);*
}
float closest = Mathf.Min(closestArr);
int arrIndexclosest = Array.IndexOf(closestArr, closest);
GameObject closestObject = yourObjectsArray[arrIndexclosest];
Not the cleanest code but should work.