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

How can I prevent InputBegan from firing in chat?

I have a game where the "P" key has a special function. I use InputBegan to check, but it seems to fire when the user types "p" in chat as well. How can I filter out keys typed in the chat box?

Full code (LocalScript in StarterPack):

player = game.Players.LocalPlayer

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.P then
		game.Workspace.remoteEvents.pKey:FireServer(player)
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

✓ Accepted answer

The gameProcessedEvent parameter will be true if the game used the input, like typing in a text box, or using i or o(they zoom in and out).

So when it's true, don't run this

player = game.Players.LocalPlayer

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.P and not gameProcessedEvent then
        game.Workspace.remoteEvents.pKey:FireServer(player)
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

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