Thank you, guys.
Braxton: the code checks the texture of the level block or wmb entity that is below the train. If the texture has a certain name, the train will move along that track. The code won't work if you are using models for your tracks.
Asse: thank you; I have replied to your pm.