Errors are an annoying thing to deal with. Unfortunately, they are also something that pops up irrespective of whether or not you want them to.
In particular, the scripting for the movement of my train was particularly error prone. If it did something, it wouldn’t do something else, and so on. However, I believe this problem has now been mostly solved.
In the initial version of the movement script, the train movement was determined by a spherical sensor coming form the train. And while it worked well for testing purposes, it was inherently difficult to work with. In addition to that, it also had a tendency to not detect some items around it. However, I managed to eventually fix the problems, by changing the way the script found the closest object.
The first version wrote the data about the detected objects to an array. The new version works in a similar way, but with extra functionality. Namely, it writes all objects with a particular tag to an array, then finds what one is closest to the train. In order to prevent reversal, the script also assigns a new tag to the objects it has passed across, which removes them from the array. The spherical sensor still plays an active roll, but in a less important way – now, it only gets used to determine whether or not the train is at the end point.