For my game, I need to completely disable the W and S keys, so players can only move to the left or right, and jump. All I’ve been able to do so far is disable movement altogether, but I can’t figure out how to disable specific keys.
This is easy to do because movement is done through core scripts.
Simply run:
ContextActionService:UnbindAction("forwardMovement")
ContextActionService:UnbindAction("backwardMovement")
Do I need to write a new script containing this, or edit an existing core script?
Write a new script.
Could you please tell me exactly what needs to be in the script, and where the script is supposed to be? I know I’m doing something wrong, but I don’t know what.
As long as that’s in a LocalScript, you can use game:GetService("ContextActionService")
to get the service I mentioned. Then, when you want to disable movement, run the code I showed.
Then how would i bind it back?
If you have intentions to bind it back, then don’t remove the context binding. What you can do instead is create an action binding with a higher priority for the W and S keys which returns Enum.ContextActionResult.Sink. This will prevent other bindings from running if they have a lower priority.
Oh, i’ve heard about this, but how would i disable the left/right movement for game pad and mobile using this?
Gamepads and mobile require a bit of a different process, since they rely on the delta distance of moving a control stick. This may require forking of the control scripts to accomplish.