Accessing same script through array of objects

I’m trying to access an array of gameobjects with the same tag (since that seems faster than findobjectsoftype) with the same script attached and change a bool on the script. The amount of objects changes often, which might be of help to know.

The only error in the console I get is this, which I’m still trying to make sense of. “IndexOutOfRangeException: Array index is out of range.
(wrapper stelemref) object:stelemref (object,intptr,object)
Car Rewind.Rewind () (at Assets/Custom Assets/Scripts/Car Rewind.js:31)
Car Rewind.Update () (at Assets/Custom Assets/Scripts/Car Rewind.js:12)”

and here is the script.

import UnityStandardAssets.Utility;
var hasSearched : boolean = false;
var RotaterScript : UnityStandardAssets.Utility.AutoMoveAndRotate[];
var rotaters : GameObject[];
var HubRewindScript : Rewind;
var i : int;

function Update(){
	if(HubRewindScript.Reverse == true){
	    if(!hasSearched){
           Search();
           Rewind();
        } 
	}
	else if(HubRewindScript.Reverse == false){
		if(hasSearched){
			UnRewind();   
        	hasSearched = false;
        }
	}
}

function Search(){
     rotaters = GameObject.FindGameObjectsWithTag("Enemy");
     hasSearched = true;
}

function Rewind(){
    for(i = 0; i < rotaters.Length; i++){
        RotaterScript _= rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();*_

RotaterScript*.m_reverse = true;
_}
}*_

function UnRewind(){
for(i = 0; i < rotaters.Length; i++){
RotaterScript = rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();*
RotaterScript*.m_reverse = false;
_}
}*_

Your “RotaterScript” array is initialized to a length of 0 and then you are trying to access elements of it in the Rewind() and UnRewind() functions. All you need to do to fix this is give it a length, which you can do at the start of the Rewind() function before the for loop - the code would look like this:

function Rewind(){
    RotaterScript = new UnityStandardAssets.Utility.AutoMoveAndRotate[rotaters.Length];

     for(i = 0; i < rotaters.Length; i++){
         RotaterScript _= rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();*_

RotaterScript*.m_reverse = true;
_}
}
Also there is no reason to put this in the UnRewind() function to Get the Components_

RotaterScript _= rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();
as you already got the components in the Rewind() function and stored them in a class level variable._