How a Roller Coaster train stays on the track
The modern roller coaster train is designed around wheel assemblies that do not differ much from ride to ride, or from manufacturer to manufacturer.
In the olden days, roller coasters used to slide on sheets of ice. Things have progressed a bit since then.
The early roller coaster trains featured running wheels and side-friction wheels. These side-friction roller coasters allowed corners to be taken. Whilst these coasters featured dips and climbs, they were never very steep, as the train was not fixed down to the track.
It was John Allen who invented the up-stop wheel, which was (and still is) the key to making roller coasters safe. The up-stop wheel meant that the train could not leave the track, and paved the way for steeper hills and, of course, inversions.
Restraints
There are two common types of roller coaster restraint with variations depending on the ride type.
The first stops riders from standing up or getting out of their seat on a coaster that otherwise would not necessarily need restraints, and the second is there to hold a rider in if the ride is intense (and the rider would fly out if there were no restraints) or as a safety measure in case the ride stalls upside down. There are also a couple of other restraint systems with specific purposes.
Many lap bars are supplemented by a basic seat-belt system to provide further safety.