Pressing H to make a GUI show up

I’m trying to make it so that whenever a player presses the H key a GUI will show up and if you press H again it will close the GUI. The script doesn’t work and nothing shows up on the output.

local userInput = game:GetService("UserInputService")
local frame = script.Parent.Frame

userInput.InputBegan:Connect(function(input,gameProcessed)
	if gameProcessed then--Prevents this from running when typing in chat
		if input.KeyCode == Enum.KeyCode.H then
			frame.Visible = true
		end
		
		if input.KeyCode == Enum.KeyCode.H and frame.Visible == true then
			wait(1)
			frame.Visible = false
		end
	end
end)
1 Like

You want to do

if not gameProcessed then

on line 4

1 Like

Also you can clean up the script by doing

local userInput = game:GetService("UserInputService")
local frame = script.Parent.Frame

userInput.InputBegan:Connect(function(input,gameProcessed)
	if not gameProcessed then
		if input.KeyCode == Enum.KeyCode.H then
			frame.Visible = not frame.Visible
		end
	end
end)
1 Like

The script works now
Thanks for helping!

Your welcome, glad that it worked out