How do disable certain keys?

when i press the arrow keys like up and down the character moves, how do i disable them?

You can set the humanoid.WalkSpeed and humanoid.JumpPower to 0 so the arrows and the A,S,W,D keys don’t move the player

1 Like

i want the humanoid to be able to use wasd to move but not up arrow and down arrow

If you mean the arrow keys only and not the WASD keys, then you can use ContextActionService:

local ContextActionService = game:GetService("ContextActionService")

local function Sink()
	return Enum.ContextActionResult.Sink
end

ContextActionService:BindActionAtPriority("ArrowKeyDisable", Sink, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right)

If you use this in a localscript in client side, it should work.

3 Likes

that worked but now my arrow keys arent being detected by userinputservice anymore

Then you can just set the humanoid jump power to 0 or use the code @WaterJamesPlough provided

Okay, so if you use some logic you could do this instead:

local ContextActionService = game:GetService("ContextActionService")

local function handleArrowAction(actionName, inputState, inputObj)
	print(inputObj.KeyCode) --Do Stuff Here.
end

local function ArrowKeyFunction(...)
	handleArrowAction(...)
	return Enum.ContextActionResult.Sink
end

ContextActionService:BindActionAtPriority("ArrowKeyDisable", ArrowKeyFunction, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right)

So it runs your Arrow Key Function, which is what you probably run in UserInputService too.

6 Likes