# How to make a basic train

Thank you, the reason I made this tutorial, is there are not many games on Roblox, based on train system

There are a couple issues here.
If it’s too heavy just make the Parts close to Massless. Massless may have some physics issues if the entire train car is Massless.
What keeps the train on the track if it goes faster? I’d suggest having another Part under the track that you could use Collision Groups to keep that Part from colliding with anything other than the rails.

Are the WedgeParts in the center of the car and you have a block at either end? I see you said to keep the Blocks 1 stud from the track, but this would cause the car to pivot or twist back and forth in the Y axis on the tracks. A better way of doing it might be to have a square Part at either end of the car welded at 45 degrees to the main train par. The square Part whould be just slightly less (like .01 stud) diagonally than the distance between the track rails. This would allow the car to stay aligned, but not twist on the track.

6 Likes

Have you tried this with multiple “cars” linked together? This may work with that kind of setup, however, may also brake due to Roblox physics if the cars are linked using phisics constratnts.

Nope and you can keep a hinge constrasit which keeps rotating, and it works, I tried to do it, don’t worry its possible

Yes you can do that, but just to make sure this is a simple tutorial, which is easy and understandable, I did not make it complex using collision groups, however once you got to know how this basic train works, you can make your custom train, so I did not include the hard ones here

Look try to keep it full touched to rails, then you notice, the train won’t move
The reason, I told to keep 1 stud is, when changing track, or turning of train, the 1 stud space gets filled and then it turns smooth as you see in the video at last

Why not 2 studs space?
As you know weight = mass * gravity
Roblox physics have gravity and mass, now if you keep 2 studs gap, the weight on the right side of the train increases, center of mass chages, and the train de-rails, or turns backwards

You don’t actually have to have a script with any kind of loop in it.
Here’s an example place I put together, with a ‘circular’ track and 2 carriages connected by a RodConstraint.
The carriages have 4 wheels with HingeConstraints in them, as well as 2 axles below the track with HIngeConstraints, and 2 wheels between the tracks to keep the carriages aligned. All HingeConstraints have the AcuatorType set to ‘None’.

Both carriages have a VectorForce in them which doesn’t require constant updating with a script. You can put a script in to change the X value of the script to make the train faster or slower, but I kept it simple.

When you test the place hop on a seat and go into both VectorForces. They should have a Force of 0,-1000,0 (the Y axis value helps keep the carriages on the track.
Set the X value of both of the VectorForce.Force to around 500 and the train should start to move forward slowly. I’ve had both X Forces up to 40,000 and the carriages stay on the track! After that it starts to get stuck when the RodConstraint goes over center, or it’ll derail, but the speed is impressive, especially for the 20 degree sharp turns of the track sections.

If you open up the Collison Group Editor in the Studio Model tab you can see where I added the green axles to the Wheels group, and all the ties to the Ties group, unchecking the boxes to keep them from colliding with each other. If you click on one of the axles you’ll see in the Properties window that the CollisionGroupID is 1. If you click on one of the Ties and look in the Properties window you’ll see the tie’s CollisionGroupID number is 2. There isn’t any scripting required for this either since it’s explained in the Collision Filtering | Roblox Creator Documentation link.

Train Experiment.rbxl (39.8 KB)

11 Likes

What, uh the game link you posted, the train does not move at all

Just have to read every part…

2 Likes

That works, but its way too complicated mechanics, and I am not a builder, so I don’t know much about making trains and forces, so I made a basic train tutorial

Not really that complicated. All of us just need to try things that are more complicated than you are used to to learn how to do them.
I tried a few things while making this system, admittedly most of which I’d already used before in other aspects, but I also made some mistakes and discovering ways to overcome those difficulties helped me out in the long run.

4 Likes

Could you give me any source or where task.wait() wouldn’t destroy the loop upon script destruction/disablation?

1 Like

`task.wait()` does not destroy the loop

What he told is, when you run a loop based on `task.wait()` then if you destroy the script inside game, it will still be running, while if you use a while wait loop, it will not work if the script is destroyed

I know, but I wanna know where he originally get that source from.

Oh ok, next time dm him, so it wouldn’t lead to a confusion

Thanks for the simple tutorial really helpful! I think I’m going to use run service for the script.

1 Like

Thanks so much for this tutorial! I’ve been trying to make a self driving train for 3 days now. I tried using constraints but it was too complicated but this tutorial was perfect! I really appreciate it.