So, I wrote a gun script, but when the player types the letters E or R in the chat, it will toggle the safety or reload the gun, accordingly.
I don't want this to happen. I've seen plenty of games that don't do this, so I know there's a way.
Here's the script. I've shortened it down considerably, to the parts that are relevant to this problem.
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then print("Key R pressed!") elseif inputObject.KeyCode == Enum.KeyCode.E then print("Key E pressed!") end end tool.Equipped:connect(function(mouse) game:GetService("UserInputService").InputBegan:connect(onKeyPress) end)
That's what the variable gameProcessedEvent
is for.
As long as it is false
, the player has not focused a TextBox
(the object you write stuff in), and so therefore isn't typing:
function onKeyPress(inputObject, gameProcessedEvent) if gameProcessedEvent == false then -- code end end
Hope I helped!
~TDP