I am trying to figure out a way to temporarily disable the left and right movements without disabling the keys entirely. I've tried using ContextActionService sink, but it disables the key entirely. That's not what I want. I want to temporarily disable the left and right movement keys so I can use the A and D keys for something else. Before you tell me to look at other posts, I have looked around many posts, but none of them seem to solve the problem entirely.
There's a good answer on the Dev Forum I've found posted by Kampfkarren Credit goes all to them.
This is easy to do because movement is done through core scripts.
1 | -- TODO: remove up and down arrows, these seem unnecessary |
2 | ContextActionService:BindActionToInputTypes( "forwardMovement" , moveForwardFunc, false , Enum.PlayerActions.CharacterForward) |
3 | ContextActionService:BindActionToInputTypes( "backwardMovement" , moveBackwardFunc, false , Enum.PlayerActions.CharacterBackward) |
4 | ContextActionService:BindActionToInputTypes( "leftMovement" , moveLeftFunc, false , Enum.PlayerActions.CharacterLeft) |
5 | ContextActionService:BindActionToInputTypes( "rightMovement" , moveRightFunc, false , Enum.PlayerActions.CharacterRight) |
6 | ContextActionService:BindActionToInputTypes( "jumpAction" , jumpFunc, false , Enum.PlayerActions.CharacterJump) |
This code was found on the ROBLOX Core Script on Github
Simply run:
1 | ContextActionService:UnbindAction( "leftMovement" ) |
2 | ContextActionService:UnbindAction( "rightMovement" ) |
Hopefully this answers your question!