"not all code paths return a value" i really try it and i really don't have idea

“not all code paths return a value” why ?

Transform nextWayPoint(Transform currentWaypoint)
{
	int ik = 0;
    foreach(Transform waypoint in trackWayPoints)
	{
		if(waypoint == currentWaypoint)
		{
			return nextWayPointinArray(ik);
		}
		ik++;
	}
}

What happens if trackWayPoints is empty? Then the iteration wouldn’t even reach the first if(waypoint ==… statement. So, you need to add a “return null” line at the very end of the function, or return fallback transform instead of null.

if either your foreach fails, or if() returns false, both don’t reach the return

You’re getting the error because your method will not return any value if the “if(waypoint == currentWaypoint)” does not trigger at all.

If you’re sure that the “if” statement will trigger, although I wouldn’t recommend it, you can do the following workaround:
Add this after your foreach loop:

return transform;

Also since you’re using the counter “ik” anyway I’d suggest using a for loop instead, like so:

Transform nextWayPoint(Transform currentWaypoint)
    {
        for (int i = 0; i < trackWayPoints.Length; i++)
        {
            if (trackWayPoints *== currentWaypoint)*

return nextWayPointinArray(i);
}
return transform;
}
Note that if “trackWayPoints” is a List< Transform > you have to replace .Length with .Count