Hello ScriptingBuilders! Indeed, I require your assistance. :D So, I have a script similar to this (taken from here:
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then print("R was pressed") end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
And the script works all fine whenever I press a key (or in this case "R"), but it also works when typing in the chat and when pressing a key does something more visual (such as cloning a ScreenGUI), it can get pretty distracting and at a point, frustrating. Now, I haven't found anything about this on the forums, so I was wondering if anyone could help me out here. The help is always appreciated. Thanks. :D -IronSpider671
The second value returned from the InputBegan
event tells you whether or not the event fired as a gameProcessedEvent - e.g. while typing in the chat. It seems you supplied a parameter for this in line 1 but you never actually checked it. CHECK IT.
function onKeyPress(inputObject, gameProcessedEvent) --Check the second parameter before continuing if not gameProcessedEvent then if inputObject.KeyCode == Enum.KeyCode.R then print("R was pressed") end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)