having problem with attack and explode

hi i am quite new to unity3d. i need help of making a simple AI script for a sphere object.
this sphere object must follow and attack player, once it collide with the player, it will explode and disappear as well as taking away one health point of the player.Secondly
i also found this script from the forum:

this is a follow and attack script:

var speed : float;
var range : float;
var numberOfAttacks : int;
var target : Transform;
var damage = 1.0;
var PerformAttack;

private var attackTime = 0.0;
private var rangeSquared : float;

function Start() {
    rangeSquared = range*range;

function Update() {
    if ( target ) {
        var moveDirection : Vector3 = target.position - transform.position;
        moveDirection = moveDirection.normalized * speed;
        transform.position += moveDirection;
        if ( (transform.position - target.position).sqrMagnitude <= rangeSquared ) {
            PerformAttack( Random.value * numberOfAttacks );

function DoAttack( attack : int ) {
    animation.Play( "Attack" + attack );

it does work but however there is an error when i played. its is written:

ArgumentNullException: Argument cannot be null.
Parameter name: target
Boo.Lang.Runtime.RuntimeServices.InvokeCallable (System.Object target, System.Object[] args)
follow and attack script.Update () (at Assets/follow and attack script.js:28)

what is the cause of the problems?and please please do help me.i’m stuck,thank you very much

target is null, meaning you never gave it a Transform, but you’re trying to use it in your script.

Assign it in the inspector through drag/drop. I recommend going through some tutorials first though as assigning a variable like this is one of the absolute basics of unity and learning to interpret the errors you get is a basic skill of programming.