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

How can you have a key set to open/close a gui but prevent it from opening when chatting?

1 answer

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.

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