Question about handling input on the client or on the server

Hello,

To get straight to the point I just want to know if it’s better to fire remotes based on input that was checked on the client, for example:

local function sendInputToServer(inputObject, gameProcessed)
    if inputObject.KeyCode == A certain key then
            DoSomething()
    elseif inputObject.KeyCode == Another key then
            DoSomethingElse()
    end
end

UserInputService.InputBegan:Connect(sendInputToServer)

Or if it’s better to fire one remote that sends the input to the server and then the server check what it should do with that input:

local function sendInputToServer(inputObject, gameProcessed)
	remoteEvent:FireServer(inputObject.KeyCode)
end

UserInputService.InputBegan:Connect(sendInputToServer)

And then the server would check what key was pressed and decides what to do with it.
The latter implies that every time a player presses a key, the remote would be fired.

How would it affect performance?

What is the point of doing this? To prevent exploiters? What big deal is there if an exploiter changes the hotkey from F to H (for example)? Players will suffer from input lag if you do this.

1 Like

I thought that it would reduce the amount of remotes I would have (Which doesn’t matter I guess).
And yeah, it wouldn’t matter if an exploiter were to change the hotkey, I just wanted to know how it would affect performance so I guess you’re right about the input lag.

Thanks.

The proper solution would be to parameterize your remote events. For example if the F key is to punch, you could do something like remote:FireServer("punch") when they press F, remote:FireServer("grab") if E is the hotkey to grab, etc. and on the server you might have

local actions = {
    punch = function(player: Player)
        -- make the player punch...
    end
}

then you get that function from the received argument.

4 Likes

Can you explain why this would be a better solution?

So that you don’t end up with duplicate remotes, of course

1 Like