So I have "e" set to open/close a gui but it also does it when someone is chatting, how can I prevent this?
This is probably a long winded method, but it works.
Note: All of this goes into a local script.
First we need to define the variables. We'll need to define the Player service, the player, the chat gui, and every child from the chat gui to the chat bar. We'll also add a "visible" variable to tell us if it's visible or not.
local Players = game:GetService("Players") local Player = Players.LocalPlayer local Chat = Player.PlayerGui:WaitForChild("Chat") local Frame1 = Chat:FindFirstChild("Frame") local parentFrame = Frame1:FindFirstChild("ChatBarParentFrame") local Frame2 = parentFrame:FindFirstChild("Frame") local BoxFrame = Frame2:FindFirstChild("BoxFrame") local Frame3 = BoxFrame:FindFirstChild("Frame") local chatBar = Frame3:FindFirstChild("ChatBar") local visible = false
Then we need a function to run whenever the player presses e:
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.E then end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Now we need the actual code. In this case, I make it so that if the chat is at full transparency, then the gui will open, otherwise it won't. However, this isn't very good in some cases, you can edit it to your liking.
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.E then if chatBar.TextTransparency == 1 then if visible then visible = not visible -- visible = not visible means that it means the opposite of what it just was script.Parent.Visible = false else visible = not visible script.Parent.Visible = true end end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Hoped this helped.