Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I disable keyboard input?

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

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.