Pathfindingsystem Script for Waypoints doesn't work.

Hey guys,
so I wrote this script:

public float speed;
public int currentWayPoint;
public Transform[] Waypoints;

Transform targetWayPoint;

void Update ()
{
	if (currentWayPoint < this.Waypoints.Length) 
	{
		if (targetWayPoint == null)
			targetWayPoint = Waypoints [currentWayPoint];
		Walk ();
	}
}

void Walk ()
{
	transform.forward = Vector3.RotateTowards (transform.forward, targetWayPoint.position - transform.position, speed * Time.deltaTime, 0.0f);
	transform.position = Vector3.MoveTowards (transform.forward, targetWayPoint.position, speed * Time.deltaTime);

	if (transform.position == targetWayPoint.position) 
	{
		currentWayPoint ++ ;
		targetWayPoint = Waypoints [currentWayPoint];
	}
}

The object should go from one waypoint to the other and so on. But as soon as I hit play the object teleports itself to the player gameobject and I don’t know why.

Change this line:

transform.position = Vector3.MoveTowards (transform.forward, targetWayPoint.position, speed * Time.deltaTime);

To be:

transform.position = Vector3.MoveTowards (transform.position, targetWayPoint.position, speed * Time.deltaTime);

tranform.forward returns direction as values between -1 and 1 and transform.position returns the coordinates of actual position of your object. Hope this clears things out, I’m quite new with these things and not english so I’m not always good with the terminology.