![Image](https://forums.factorio.com/images/ext/ff9a9201d6384e96573a8f0e8722c2db.jpg)
https://en.wikipedia.org/wiki/Level_crossing
There is quite a number of train deaths that could be prevented by this simple solution.
It could be even "anti-crossing", like not the red light for a car or a tank (in a case of approaching train), but the red light for the train in a case of approaching player. Or be it both - for the choice of the player.
It could be even same "gate" element, only parallel to a railway, not perpendicular, with counter-behaviour - raising up when the train is on the block.