Lowest delay way to connect functions to key presses

what is the best way to connect functions to key presses in the least delayed way? The least delay, the better. I’m working on custom movement for… Something… And I need lowest latency possible.

1 Like

I believe it’s easier to connect functions with CAS instead of UIS.

1 Like

So, I tested this and it is pretty clear that ContextActionService is much faster everytime.

Code I made for testing:

--!strict
local cas: ContextActionService = game:GetService("ContextActionService")
local uis: UserInputService = game:GetService("UserInputService")

local function handle_action(_, input_state: Enum.UserInputState)
	if input_state ~= Enum.UserInputState.Begin then return end
	
	print("cas:", tick())
end

local function handle_uis(key)
	if key.KeyCode ~= Enum.KeyCode.X then return end

	print("uis:", tick())
end

uis.InputBegan:Connect(handle_uis)
cas:BindAction("input", handle_action, false, Enum.KeyCode.X)

Which simply prints tick of the server.

well, it shows that the is some delay improvement… I guess that answers my question