There is a conflicting script stopping it from working right.
you don't need any script for this, and your map has to stay on a single tileset.
based on your map, you'll need FIVE events. The bridge event and four switch events in the four directions (your map screenshot only shows three switch events, the bottom one is missing).
1) bridge event.
give the first page a tile of the railroad as the sprite - you have to scroll down to the bottom of the spritelist to get the tiles.
set priority to "below characters"
make a second page
on the second page, set the image to the same tile as the first page
set priority to "above characters"
set condition to a switch "going below bridge"
that's all, no content needed at all.
2) create the two events above and below the bridge
both are set to priority below character
both are triggered by player touch
both have only a single command: control switch "going below bridge"= ON
no image, nothing else
3) create the two events to the left and right of the bridge
both are set to priority below character
both are triggered by player touch
both have only a single command: Control switch "going below bridge" = OFF
Finished. If the railroad is passable in the tileset (and has directional passability going only along the rails) this will work as you want.
if you want this on other maps where the structure is different:
just copy the bridge tile as often as you need to bridge the gap
move the switch controls to all approaches to the bridge (might have to copy them for larger zones)
And if the tile used for the bridge is multi-directional and you can't use directional passability, simply block the unwanted ways off the bridge with invisible events on priority "same as player"