Powerups can still be used while chatting

So in my game, there are powerups that activate with Q and E.

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
	    if inputObject.KeyCode == Enum.KeyCode.Q then
				tool["Metal Powerup"]:Play()
		        speed:FireServer()
		elseif inputObject.KeyCode == Enum.KeyCode.E then
				tool["Metal Powerup"]:Play()
		        defense:FireServer()
	    end	
end)

The code is fine and everything, but a huge problem occurs when a player is typing, and when they press Q or E while typing, the powerups will activate. How do I make it so that it will not trigger when a player is chatting? It can be frustrating to players, so I would really appreciate the help. This script is inside a tool.

You forgot to add gameProcessedEvent to your if statements
also next time search for your problem here before posting it.

There are several methods you could use to get around this.

  1. ContextActionService - Using BindAction as that doesn’t fire when you’re typing. (what i recommend)
  2. Checking gameProcessedEvent (the second parameter passed through InputBegan)
  3. Checking if they’re selecting a TextBox with GetFocusedTextBox

i feel like a real dum-dum for not searching it up, sorry guys, but thanks for the answer