IndexOutOfRangeException: Array Index is out of range Help

Hey, could someone help me solve this error in my script, saying:

IndexOutOfRangeException: Array index is out of range.
MultipleWaypoints+$RotateTowards$88+$.MoveNext () (at Assets/Train/AItrainscripts/MultipleWaypoints.js:28)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
MultipleWaypoints:Update() (at Assets/Train/AItrainscripts/MultipleWaypoints.js:21)

It occurs when my train model reaches the last waypoint.
I do know its saying the error is at line 28, but i have no idea what to change or what the error actually is.
Help would be appreciated.

This is the script:

var waypoint : Transform;

var speed : float = 20;

private var currentWaypoint : int;

function Update () {

if(currentWaypoint < waypoint.length){

var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target - transform.position;  

var velocity = rigidbody.velocity;



if(moveDirection.magnitude <=1.0){

	currentWaypoint++;

}

else{

    velocity = moveDirection.normalized * speed;

    

}

}

rigidbody.velocity = velocity;

RotateTowards();

}

function RotateTowards () {

var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target - transform.position;

while(Vector3.Distance(target, transform.position) >= 1.5){

transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection), 0.5* Time.deltaTime);

transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

yield;

}

}

It tells you that your currentwaypoint index is not valid. Say if you have 5 waypoints, your index can only be in the range 0-4.