InputBegan, along with InputEnded, returns another value that can be used to tell when the player is chatting or doing another task with things such as the menu or chatting.
This value is called 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
uis.InputBegan:Connect(function(key,g)
if g then return end
if key.KeyCode == Enum.KeyCode.E then
if gui.Enabled == false then
gui.Enabled = true
else
gui.Enabled = false
end
end
end)