Not detecting E when its typed on chat

Hello everyone, I have a shop which opens pressing e, the problem is that the shop opens when you type in chat too, how do I fix this?

Code:

useri.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if (camera.CFrame.Position - model.PartUI.Position).Magnitude <= 20 then
			for i, v in pairs(ui:GetDescendants()) do
				if v.ClassName == "Frame" or v.ClassName == "ScrollingFrame" or v.ClassName == "TextButton" or v.ClassName == "TextLabel" or v.ClassName == "ViewportFrame" then
					v.Visible = true
				end
			end
			model.PartUI.BillboardGui.Frame.Visible = false
			model.PartUI.BillboardGui.Frame.TextLabel.Visible = false
		end
	end
end)

The structure of the code will be greatly appreciated in order to find a solution.

1 Like

Added the script

30characters.

I’m assuming you’re using UserInputService input events, correct me if I am wrong?

In the input events, the second argument is gameProcessedEvent which describes if the game has processed that input previously.
This means if you’re typing in a TextBox, for example, it’d be true as the game has processed that input.

You wanna make a check to see if it’s true and if it is you stop the code there.
Here would be a code sample how it could look like:

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end

	-- ... rest of the code here
end)

This is how Developer Hub describes 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 . This is also true for input events connected via ContextActionService

2 Likes

I’m pretty sure that using context action service would resolve this issue. I think that you can also use the gameProcessedEvent parameter to stop this from happening.
Game Processed Event just detects if you want the script to run if you are typing in chat.

If you want to fix your script, you should write:

 useri.InputBegan:Connect(function(input, gameProcessedEvent)
       if gameProcessedEvent then return end
             if input.KeyCdoe == Enum.KeyCode.E then
                  -- Put rest of code here
             end
 end)
1 Like