There’s some code that disconnects and clears the connection from the table when the driver exits the seat (although this will change, because the driver of the train will depend on who’s first to turn the key)
I’ve seen this part of the code, yeah. This still makes the code reliant on which order you call the functions in, and only permits a single player to drive a train at any given time. Not that bad if it’s called on the client, but still error-prone if you happen to call the drive and leave functions out of order.
How should I do the remote events instead?
You ought to ensure that the player input gets validated in some way.
In my current project I create a remote event for all events (building, claiming a plot, etc.). I’ve also created a small module that binds a remote event to 1 or more functions, based on which types the parameters are. Any call with invalid types is immediately discarded. After the bound function with the relevant parameters gets found and called, I make sure to add some verification logic to ensure that the player is allowed to execute the current action.
For your game this might be overkill, or you might need more automatic verification. You could add an automatic check that the given player is the owner of any passed train value, for instance.
The -100 is an extra position on the throttle gui, which is another way the emergency brake can be activated. That script can be found in the screenGUI under throttle as local script, the drive mode one is just to handle the Forward and Reverse lever.
It’s currently a magic number you might not know the use of if you look at the code for a first time. If you’re developing this solo you’ll be fine leaving this in, but if you intent on working together with other programmers later on it’s good practice to define this value in a single location. This’ll also save you lots of trouble if you need to modify this number sometime later.
That module is handled on the client, the train is player driven not server driven btw.
If the train system is competitive, I recommend changing this to be handled on the server to prevent exploiters. If it’s just a casual train system, this will once again be fine to keep as it is.
If you’d like to give it a test play to see how things work then I’d be more than happy to give you a quick tutorial.
Sure I’d be up to play this sometime. Maybe this weekend, on a saturday?
How is my DoorsService module?
There’s a couple more modules that may need to be looked at like,
ReplicatedStorage.CustomServices.TrainService.DriversConsole
ReplicatedStorage.CustomServices.PIDs (Passenger Information Displays, not yet finished and only visible to the client who sets it, when I want to make it server sided at some point)
I’m afraid I don’t have enough time to take an in-depth look at your entire project.