Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I bind to a movement key on startup?

Asked by 7 years ago
Edited 7 years ago

This question has been solved by the original poster.

I want to use the following code to bind the w key to a certain function:

contextAction:BindAction("W function",function()end,false,Enum.KeyCode.W)

However, when I try to use this at the start of the game, the w has not yet been bound by the default character movement binding. So, if I try to use this binding immediately, it would just get overridden by the the later default binding.

So, I came up with two possible solutions, and I would like to have your opinion/solution:

1] unbind the default character movement binding somehow (I don't know how to access it) and then rebind after I finish the function I want to do, or

2] force the binding of the character movement binding at the start of the game so that I can temporarily disable it (Enum.userInputState.Cancel) when I bind another function and then re-enable it once I end my other function.

0
If you don't want the character to move during this, you could just anchor its head or set its walk speed to 0 RubenKan 3615 — 7y
0
Oh, that's a good idea because I didn't unbind the other keys (a,s,d). Thanks for the advice! WingedHorizen201 124 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

So, I found a solution that seems to work. Although, I would still like to have the opinion of a veteran.

1] Make your script wait for the Keyboard Movement Module Script located in Players>PlayerName>PlayersScripts>ControlScript>MasterControl>KeyboardMovement.

2] Bind your function and unbind it when you are done so that the character movement binding can continue.

0
I agree with this method. You can also take that script as its running, and copy, paste it into your code( after you stopped the test run). This method is mentioned in the Roblox wiki on the subject of using Contextual input. JasonTheOwner 391 — 7y
0
I couldn't find any article on the Roblox wiki about this method, so could you post a link to it? WingedHorizen201 124 — 7y
Ad

Answer this question