Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

UserInputService! Is there a way to not trigger the "InputBegan" event while chatting?

Asked by
Redbullusa 1580 Moderation Voter
10 years ago

Every time I chat and click on the KeyCode for my script below, it triggered the "InputBegan" event. Is there a way to make the script "postpone" (in a sense) the event, so that the function connected to the "InputBegan" event doesn't run while chatting?

1-- Local Script located in game.StarterGui
2Player = game.Players.LocalPlayer
3UIS = game:GetService("UserInputService")
4 
5UIS.InputBegan:connect(function (InputObject)
6    if InputObject.KeyCode == Enum.KeyCode.F then
7        print("F is pressed!")
8    end
9end)

This is what happened when I was chatting. Notice the output.

1 answer

Log in to vote
6
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The InputBegan event returns two values.

  • 1) - The input that fired the event.

  • 2) - Whether or not the event was fired as a "gameProcessedEvent".

Notice the second value? It's a bool. And a "gameProcessedEvent" is something like.. chatting(:

See the connection? All you have to do is make sure the second parameter is false before going on with the code(:

01local Player = game.Players.LocalPlayer
02local UIS = game:GetService("UserInputService")
03 
04UIS.InputBegan:connect(function(InputObject,Processed)
05    --Make sure the second parameter is false
06    if not Processed then
07        if InputObject.KeyCode == Enum.KeyCode.F then
08            print("F is pressed!")
09        end
10    end
11end)
2
Thank you so much for this! Now I can completely ditch KeyDown events with confidence! xD Redbullusa 1580 — 10y
0
This helped and was simple. Thanks. TJim_YT 0 — 5y
Ad

Answer this question