What's the most optimal way to translate client inputs to the server?

So, my question isn’t really an issue and more so a heads-up on whether what I’m doing is good practice and the optimal way to handle things.

Specifically, I’m looking into the most optimal way to translate client-sided inputs to a server-sided combat script. I want to know if what I’m doing is the best way to achieve the fastest possible response time without taking a player’s ping into account.

Currently, how I’d handle inputs is by binding them client-sided via ContextActionService:BindAction(...)

and then executing checks and firing a remote in the function itself

example for the client side:

ContextActionService:BindAction("Dash", Dash, false, Enum.KeyCode[KeyBindData.Dodge])

local function Dash(ActionName, InputState, InputObject)
	if ActionName == "Dash" then
			RemotePath.Dash:FireServer()
	end
end

-- this isn't actually a script in my game but just an example of how I'd usually structure things.

If there are any faster / better methods, please let me know.

Things I’ve tried already: (mostly just the no-brainer things)

  • Reducing the number of passed arguments within the remote event
  • Handling the input over a remote that passes it to a server script that has specifically defined functions

example:

RemotePath.Remote.OnServerEvent:Connect(function(Player, Action, ...)
	if Actions[Action] then
		Actions[Action](Player, ...)
	else
		return
	end
end)

NOTE: For the thing I tried up here, I asked an AI to calculate which was faster and got told that handling it like that was faster, so most of the time I’ll structure my scripts like that

1 Like

The general rules for minimizing network latency is:

  1. Minimize the size of the data.
  2. Reduce how many requests you make.

Okay, you said you reduced the number of passed arguments, but you can also consider passing a lot of things at one time rather than passing pieces of it many times. Depends on what your code is doing.

For the thing I tried up here, I asked an AI to calculate which was faster and got told that handling it like that was faster, so most of the time I’ll structure my scripts like that

I don’t see that there is any performance difference in any of the code you gave. It just seems like the AI told you to use a dictionary so that way you don’t make a million if-statements based on what action to take.

Perhaps, consider sanity checks on client-side to avoid requests whenever as well.

without taking a player’s ping into account

Unfortunately, the player’s ping affects that it goes through to the Roblox server too. You can’t fix that. Just go for good enough, not “fastest possible”.

Yes, you could optimize the heck out of the size of the data, compression methods, etc, if you want. But, the remote events are designed for frequently talking back and forth, don’t try to overengineer it. Maybe more background context will help if this feedback is too generic for you.

1 Like