Handling client-side input for custom vehicle

So I have a helicopter, and it has a regular Seat instance inside of it. When the player sits inside, they are given network ownership of the vehicle, so latency is eliminated alongside making the vehicle’s movements replicate to the rest of the server. (EDIT: If I understand network ownership right :P)

How would I go about using ContextActionService to bind a set of controls to the player once they sit in the helicopter seat? Additionally, is it safe to use network ownership in this scenario? I have heard using RemoteEvents causes a large amount of input lag for many users.

1 Like

You can use a script and localscript with Character.Humanoid.Seated to detect when the player sits, and the script sets network ownership to the player. This means they can move it around, and that’s what the localscript is for. If the character is seated it starts a loop that detects input. Using BindAction you bind whatever functions are used to fly the heli to the proper keys. Personally, I would use UserInputService, but I haven’t really used CAS, so I don’t know what special features it has that uis doesn’t have. :woman_shrugging:
It is the best way to handle this scenario, but not the safest way, however there are times it is better to have a better user experience over having exploit protection, and this is one of those times. If you want to make it “safer”, you can add distance checks that ensure the heli is not going over some speed cap. (example, store the OldPos of the heli and compare that with the current position, if it’s over some value for the deltaTime since you last checked, return to the old position.)
Yes, using remoteevents causes a lot of input lag, and is often discouraged just because of how much it detracts from the user experience. You want something that is responsive but the server still can intervene, and this system with a distance check is a good place to start.

2 Likes

Thanks for the detailed answer! I was thinking of using CAS to bind key presses to the user when they sit. So you just have a LocalScript that constantly checks if the player is sitting and inside the helicopter?

It doesn’t “Constantly check” but rather listens to an event that is triggered, and the event can be either a humanoid sit change (documentation here) or a remote event that the server fires to let the client know it’s in a seat.

1 Like