Instantiating Prefab Basics?

I am not new to scripting, but I am new to Unity’s scripting, and i have to say that it seems kind of picky.

So i have looked around and i get the code structure but i still feel lost. I have a prefab, and i have attached this Javascript to it:

var Ball : Rigidbody;
var MaxBalls = 20;
var spawnWait = 1;
var NumOfBalls = 0;

function Start () {

	InvokeRepeating("spawnBall", 2, spawnWait);
	
}
function spawnBall () {

	while (NumOfBalls < MaxBalls+1)
	{
		NumOfBalls++;
		var clone : Ball;
		clone = Instantiate(Ball, transform.position, transform.rotation);
	}
}

I keep getting this error: The name ‘Ball’ does not denote a valid type (‘not found’).

Please help?

Ball should be a transform instead of a rigidbody

Nope. That is not the problem. You can instantiate as long as it’s of type Component. So doing so will not cause any problem. Only problem is with this line

var clone : Ball; // This line
clone = Instantiate(Ball, transform.position, transform.rotation);

Because Instantiate returns a type Object and you are assigning it a type Ball. So you can’t.

You can however do this.

var clone : GameObject;
clone = Instantiate(Ball, transform.position, transform.rotation) as GameObject;