I never worked with paths, but I think the problem is, that node is null after the last node was reached. There is no node with the number 0, wich could be a problem for path_nextnode();.

I would suggest, to add a simple if statement:

if(distance < 25)
{
node = path_nextnode(my,node,1);
if(!node){node = 1;} //if the last node was reached, start again with the first one
path_getnode(my,node,pos_node, null);
vec_to_angle(temp_pan,vec_diff(temp,pos_node,my.x));
wait(1);
}


I hope this helps,
Slin