How do I make a cart that stays on a rail?

Not sure if this would be scripting or building, so Ima just put it here for now.

Any how, How do I make a cart that stays on a rail?
Im bored and I want too :3
Thanks!

You could add cylinder “stoppers” on the bottom of the cart, making it more stable on the track, but if you meant stay as in a real rollercoaster then I am not sure. You could add a part that wraps around the track.