Is firing a remote for each keyboard/mouse input bad & performance heavy?

I am creating a framework for a combat game, and the way I make inputs for attacks is that for each input, it fires a remote event to the server then the server checks for attacks on a moveset list that match desired inputs like the keybind, and the state. Is it too impactful on performance to fire a remote event for each input, or is it fine the way it is?

How inputs are sent to the module script that fires them to server:

--//Variables
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local inputReciever = require(game:GetService("ReplicatedStorage"):WaitForChild("InputReciever"))

--//Function
local function SendInputKey(keycode, state)
	if not player.Character then return end
	inputReciever:Input(player, keycode, state)
end

--//Inputs
uis.InputBegan:Connect(function(key, gpe)
	if gpe then return end
	local keycode
	if key.KeyCode ~= Enum.KeyCode.Unknown then
		keycode = key.KeyCode
	elseif key.UserInputType ~= Enum.UserInputType.Keyboard then
		keycode = key.UserInputType
	end	
	if not keycode then return end
	SendInputKey(keycode, "Began")
end)
uis.InputEnded:Connect(function(key, gpe)
	if gpe then return end
	local keycode
	if key.KeyCode ~= Enum.KeyCode.Unknown then
		keycode = key.KeyCode
	elseif key.UserInputType ~= Enum.UserInputType.Keyboard then
		keycode = key.UserInputType
	end	
	if not keycode then return end
	SendInputKey(keycode, "Ended")
end)

How inputs are fired to the server:

local InputRecieverModule = {}

local Input_Remote = script:WaitForChild("RemoteEvent")

function InputRecieverModule:Input(player, keycode, state)
	local char = player.Character
	if char:GetAttribute("Stun") or char:GetAttribute("Endlag") then return end
	
	Input_Remote:FireServer(keycode, state)
end

return InputRecieverModule

I would provide the server part as well, but I haven’t gotten to creating it yet

yeah that will probably be fine

ok, thanks for some assurance, what ill probably do is just whitelist some inputs so that remotes dont fire whenever you press w,a,s,d, etc

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.