When you view the variables they will be correct, but they are not correct in the tick (1/60th of a second) that you look for the path. Your code works like this :
Spawn villager
Find path to town.x using default villager.gotoUID (they will all find a path to the same town)
Change villager.gotoUID after path already found
It does event 15, then 17/18, then 16.
You need to wait for a bit to allow all the variables to be set and by that I mean probably 1 second but even a wait of 0.1 secs in the on created event above find path would show it working.