UserInputService Functioning when Player is Chatting

Hey Guys!
I am currently helping develop a game, and I ran into a problem with UserInputService and in-game Roblox Chatting. Whenever I press a keybind or hotkey or whatever you would like to call it while chatting in Roblox Chat, the function of that key in general fires, which is not favorable. I don’t think it is necessary to show screenshots or videos, because this is mostly straightforward. Here is the script:

local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Respawn = game:GetService("ReplicatedStorage"):FindFirstChild("Respawn")
local rKey = Enum.KeyCode.R

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == rKey then
		Respawn:FireServer()
	end
end)

I will show the server script if needed.

To prevent this from happening you would use GameProcessedEvent.

For example:

UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
    if GameProcessedEvent then return end

    if Input.KeyCode == Enum.KeyCode.E then
        ...
    end
end)
2 Likes

im assuming GameProcessedEvent means the key was being used in some other way that roblox handles?

GameProcessedEvent indicates whether the game engine internally observed this input and acted on it. Generally this refers to UI processing, so if a button was touched or clicked from this input, GameProcessedEvent would be true else, it would be false.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.