Sending userinputservice to server

so i searched around the devforum for how to make the userinputservice serversided and i have found the solution,

its simple you just send all the inputs to the server but im worried that if some player used a macro it would rapidly send it to the server and basically lag the server. so thats the issue will sending the input lag the entire server due to the remote events?

1 Like

Yes, lots of events will spawn lots of threads which will cause lag. You can combat this by putting rate limits on RemoteEvents coming from players. You could limit a player to sending fewer than 10 input-related remotes per second, which I think is reasonable for most games.

2 Likes

and how can this be made?

what im thinking now is using a cooldown for each player

1 Like

Yeah, userinputservice is client sided for a reason. Don’t do anything on the client that could be exploited, you don’t need to send every input to the server.

2 Likes

Its easier if I just give you an example so give me a few mins.

2 Likes

take your time, thanks for the help so far

You can do it this way to create a shared limit for all events going through InputBegan, but you could also use this with contextactions or inputended events by routing them through the same function.

function ActualInputHandler(...)
	--Your actual input logic here
end

local eventsPerSecondLimit = 10
local events = {}

--Initialize events list
for i = 1, eventsPerSecondLimit do
	events[i] = tick()
end

function RateHandler(...)
	--Check rate limiting
	
	--Time of input
	events[#events + 1] = tick()
	
	--Limit length of recorded events to 10
	if #events > eventsPerSecondLimit then
		table.remove(events, 1)
	end
	
	--How fast were the last 10 inputs given?
	local delta = events[#events] - events[1]
	
	print("Delay: " ..delta)
	
	if delta > 1.0 then
		print("Sending")
		ActualInputHandler(...)
	else
		print("TOO fast. Slow down!")
	end
end

UserInputService.InputEnded:Connect(RateHandler)
1 Like

ill test it now, thanks

character limit

it worked thank you for the help!

1 Like

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