Hello developers! I am making a game where you are only supposed to use the A and D keys, otherwise the game will break. Is there a way to turn the others off? I can’t script and couldn’t find tutorials either.
There was a post about this a long time ago, you could try this out
This is the code they used
local ContextActionService =game:GetService("ContextActionService")
local FowardMovement = Enum.PlayerActions.CharacterForward
local BackwardMovement = Enum.PlayerActions.CharacterBackward
local function Sink()
return Enum.ContextActionResult.Sink
end
----Sink forward movement
ContextActionService:BindAction("SinkFowardMovement", Sink,false,FowardMovement)
----Sink backward movement
ContextActionService:BindAction("SinkBackwardMovement",Sink,false,BackwardMovement)
It’ll still most likely work even if roblox changes the names of the PlayerControls in the future
The script does not work for me
Did you put it in a local script in StarterPlayerScripts?
Yes. Now, I managed to make it do… something. So when I go in the game now, I can not move at all. Then if I wait for a couple seconds I can, but also with W and S.
I’m hopeless i know
Edit: I figured out the waiting problem, but now i can still move with W and S.
Maybe try?
repeat wait() until game:IsLoaded()
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:UnbindAction("moveForwardAction")
ContextActionService:UnbindAction("moveBackwardAction")
Tried it, but nothing changed.
Odd, it works for me. Maybe put this code
local ContextActionService =game:GetService("ContextActionService")
local FowardMovement = Enum.PlayerActions.CharacterForward
local BackwardMovement = Enum.PlayerActions.CharacterBackward
local function Sink()
return Enum.ContextActionResult.Sink
end
----Sink forward movement
ContextActionService:BindAction("SinkFowardMovement", Sink,false,FowardMovement)
----Sink backward movement
ContextActionService:BindAction("SinkBackwardMovement",Sink,false,BackwardMovement)
As a localscript in startergui?
Also doesn’t work, so that’s pretty weird. It causes me to not be able to move at all.
Edit: just checked. if i wait for like half a minute it does work. odd that i have to wait so long, but that’s fine. Thanks!
Anytime! If you have anymore issues don’t be afraid to make another post! And I’m not sure why for you requires you to wait for 30 seconds but it worked instantly for me, it’s probably other scripts delaying it?
Also so y ou know, this only works for keyboard movement, this doesn’t work for Touch Input and controllers
Yes I just fixed that by accident lol.
I forgot to delete the script of one of my previous attempts. It was delaying it.
Alright. That’s fine. The game was meant for pc anyways. Thanks for the help!
Thank you, I searched around the web for the answer to this problem, but had no luck until I read your response. It really helped me