Enemy AI Patrol Points Array Index Out of Range?

I made a script to get my enemy to patrol between three different spawn points. It works, but when he reaches the third spawn point, even though he keeps going it gives me an Array Index out of Range error on line 31, the rotation to face the next patrol point?? Where did I screw up?

public class EnemyAttack : MonoBehaviour 
{
	public Transform[] patrolPoints;

	public Transform target;
	public int movementSpeed;
	public int rotatationSpeed;

	public float moveSpeed;

	private int currentPoint;

	void Start () 
	{
		transform.position = patrolPoints[0].position;
		currentPoint = 0;
		target = GameObject.FindGameObjectWithTag("Player").transform;
	}
	
	void Update () 
	{
		if(currentPoint >= patrolPoints.Length)
		{
			currentPoint = 0;
		}

		if(transform.position == patrolPoints[currentPoint].position)
		{
			currentPoint++;
		}
		transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(patrolPoints[currentPoint].transform.position - transform.position), rotatationSpeed * Time.deltaTime);
		transform.position = Vector3.MoveTowards(transform.position, patrolPoints[currentPoint].transform.position, movementSpeed * Time.deltaTime );

You’ve just got the logic a bit wrong I think, try this:

         if(transform.position == patrolPoints[currentPoint].position)
         {
             currentPoint++;
             
             if(currentPoint >= patrolPoints.Length)
             {
                 currentPoint = 0;
             }
         }

this is the problem:

if(currentPoint >= patrolPoints.Length)

say you have 4 points, “currentpoint” can be 0 to 3. but patrolPoints.Length= 4 because you have 4 element in your array.

you need to change it to:

 if(currentPoint >= patrolPoints.Length-1)