As a beginner scripter, one of the first milestones is scripting your first car. It’s a really exciting time for me, as just today I learned how to used RemoteEvents. This way I can detect the inputs of the player, and send it on over to the server to move the car. While coding this, I came across a thought, and that was:
If I have 30 different players all driving their respective car, will that lag the server?
And then I spiraled into possibilities, I could create a localscript that both takes the input of the player and then moves the car all on its own, only transmitting the position and orientation, or CFrame, to the server, I have no idea how to do this, any ideas?
You can pass values as arguments to the FireServer and FireClient methods of RemoteEvents (firing RemoteEvents without arguments works fine if you don’t need to tell the client/server anything it doesn’t already know). Here’s an example, sending a value from the client to the server:
Client
local valToSend = "Hi!"
script.RemoteEvent:FireServer(valToSend)
(Where the LocalScript is the parent of a Script and RemoteEvent without any name changes)
More Importantly, You don’t need to replicate client-side values across to the server using RemoteEvents in this case. Using a server-side script to do this instead will cause these changes to originate on the server and then replicate to the client.
Detecting inputs shouldn’t require a LocalScript either, since the VehicleSeat (block you can sit on, comes by default with that classic Roblox speed HUD) has Steer and Throttle properties that are based on the input of the driver and can be read by server scripts without any issues. You’ll probably still need a LocalScript for other inputs (ex. turning on headlights, engaging a parking brake).
To go on a small tangent, try to use server-side values & calculations as much as possible - I like to treat it like everything on the client can be manipulated to make exploiting harder.
It’s probably better in terms of lag to handle these things on the server. I like your approach - I also optimize my code by making sure it would be able to run on a briefcase laptop from the 90s. In this case though, I don’t think this would be a problem.
The only thing I can think of in terms of optimization is (maybe) using ModuleScripts to make your code less repetitive, but either way you’re probably fine (especially for a rough draft).