NullException Error With Array of GameObjects

I am trying to create an array of gameObjects, which is then referenced by a function that turns on the renderer and collider of each when called. However, when I playtest, occasionally it will work for one of the cylinders, and the rest of the time it throws a NullReferenceException. I was wondering if anyone can see what I did wrong? I’ve looked through other similar questions and still cannot figure out why it is doing this.

Here is the instantiation (for reference, there are four cylinders/rings in the scene).

private var Rings : GameObject[] = new GameObject[10]; //array of rings

function Start () {
//count rings
 	totalAmount++; //totalamount = totalamount +1;
 	Debug.Log("Total Amount of Rings = " + totalAmount);
 
        Rings[totalAmount] = GameObject.Find("Cylinder." + totalAmount);
		Debug.Log("Found game object: " + totalAmount);

}

And here is the function where it is called.

function TurnOnAllRenderers(){ //turn all ring renderers back on if the player is reset to beginning
	for(var i = 1; i <= totalAmount; i++)
	{
	Debug.Log("turn on = " + i); 
	 Rings*.renderer.enabled = true;* 

_ Rings*.collider.enabled = true;_
_
}_
_
}*_

Your array only stores one item in the Start at the index 1 so your loop in the method does not find anything.

EDIT: based on your comment, the error is different. So I would guess totalAmount is static since it increases as expected. But your array is private You actually have an array for each script.

So the first script1 places object1 in slot 1 of array1 using totalAmount, but script2 places object2 in slot 2 array2 using totalAmount.

Solutions:

Easy: make the array static.

More complex: Store the array in some Manager script and use GetComponent and find the array:

var manager :Manager;

function Start(){
    manager = GameObject.Find("Manager").GetComponent(Manager);
    manager.array[totalAmount] = object;
}

Also, try to start from 0 as you may get out of bound.

Use update for increasing the total amount - or use a loop to do this.
Also start a loop at index 0.

Your totalAmount is 1. So your loop goes from 1 to 1. → the loop is doing nothing