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

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

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?

-- Local Script located in game.StarterGui
Player = game.Players.LocalPlayer
UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function (InputObject)
	if InputObject.KeyCode == Enum.KeyCode.F then
		print("F is pressed!")
	end
end)

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

1 answer

✓ Accepted answer

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(:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(InputObject,Processed)
	--Make sure the second parameter is false
	if not Processed then
		if InputObject.KeyCode == Enum.KeyCode.F then
			print("F is pressed!")
		end
	end
end)

2 comments

2

Thank you so much for this! Now I can completely ditch KeyDown events with confidence! xD

0

This helped and was simple. Thanks.

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