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

How do I disable keyboard input?

Asked by
Avectus 120
9 years ago

I'd like to disable keyboard input for a few seconds for the key 'q' and then enable the player to use q again.

Could someone tell me how I would do this or if this is possible?

Thanks.

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

Create a variable that checks if you can run the function or not.

--Must be in a LocalScript inside StarterGui or StarterPack.

ableToPressQ = true --The variable that checks if they are able to run the code.
mouse = game.Players.LocalPlayer:GetMouse() --Gets the mouse for the KeyDown event later.

mouse.KeyDown:connect(function(key) --Creates the function and event to fire when a key is pressed.
    if ableToPressQ == true and (string.byte(key) == 113 or string.byte(key) == 81)) then --Checks if the variable lets you press Q or not, and checks if the actual key pressed was indeed the letter Q.
        --Your Code
    end --Ends the if statement.
end) --Ends the function.

If you want to change it so the player cannot press Q, then put ableToPressQ = false where you need it.

If I helped you, be sure to click the Accept Answer button below my character!

Ad

Answer this question