I am attempting to disable arrow key movement for my game in Roblox, however I have attempted to search the developer hub and the forum finding only one solution which was to disable movement in certain directions entirely which isn’t what I require. What I require is arrow keys for movement completely disabled.
Okay, so the user movement is controlled by a module script called Keyboard under PlayerScripts. So first, I ran solo in studio, copied the PlayerModule from the Player Scripts, and then put it into StarterPlayerScripts.
Then, open up PlayerModule -> ControlModule -> Keyboard
That entirely pertains to handling user movement from the keyboard. Since the up & down arrow are the only arrow keys that have an effect on movement, I simply added an if statement to verify that the request wasn’t coming from either of those keys.
I’ve attached the updated script. Simply put it in StarterPlayer → StarterPlayerScripts
PlayerModule.rbxm (124.0 KB)
You don’t need a weird solution like above. In fact, it’s not recommended that you fork the PlayerModule unless you’re capable of keeping up with updates yourself. It’s better to handle what you can without forking something that’s bound for change.
All you need is the ContextActionService. It’s that simple. From here, you just need to sink the input of the arrow keys and you’re done. No downloading anything, no forking, nothing. One LocalScript, few lines of code, you’re all set.
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindActionAtPriority("DisableArrowKeys", function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right)
cc @Capt_George
Haven’t had the chance to test, but if it works I totally agree it’s better
Not much experience on hand w/ that and didn’t ever experiment before hand, just played around and figured that out
Yeah, just drop it in Studio and have a go. You’ll notice that you can’t move around with the arrow keys.
Typically you should only fork the PlayerModule if you need to make large codebase modifications. If you’re going for something as simple as disabling input, you can use items that are already readily available. In this case, ContextActionService is super handy.
Yep, only experience I have is forking the popper cam for advanced/a lot of modifications.