Accessing other objects' scripts.

I want to access/modify scripts of objects I have found with an overlap sphere. Here is a sample:

var testScript:TestScript;
var detected:int = 0;	
function Start () {

}

function Update () {
	
		
	var hitColliders = Physics.OverlapSphere(transform.position, 5);
			
	for (var i2 = 0; i2 < hitColliders.Length; i2++) {
		detected++;		
		hitColliders[i2].transform.name = ("Collider "+detected);
		if (i2==10||i2==15||i2==17||i2==22){
			testScript=hitColliders[i2].transform.GetComponent(TestScript);
		}
		testScript.increase();
	}
}

…and here is the script I’m trying to access:

var num:int=0;
function Start () {

}

function Update () {

}

function increase(){
num++;
}

I get a null reference exception when I try to call the increase function from the main script.

your line

testScript.increase();

needs to be in the preceding if block otherwise testscript doesn’t have a meaningful value