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

How do you make a keybind that doesn't fire when you type in chat?

Meaning that if you're typing and you type a letter that has a keybind, it won't fire the action. For example, I have this line of code:

if key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.Up then

Currently, it will fire if "Up" or "W" is pressed, even when you are typing. How could I fix this?

NOTE: I wrote this to handle inputs:

game:GetService("UserInputService").InputBegan:connect(function(key)

1 answer

Use GetFocusedTextbox to check if the player is currently typing into a textbox (Yes, this includes the textbox for chat)

So what you would do is:

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:connect(function(key)
	if not UserInputService:GetFocusedTextBox() then -- if it returns nil (i.e. not currently in a textbox)
		--TO-DO whatever you want to implement
	end
end)

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