Trying to make a key bind that displays a screen GUI

when I try to bind a key bind to a screen GUI and use the key bind it enables the GUI I want the same key bind to be able to disable the GUI this is the method I tried but it doesn’t work

local GUI = script.Parent.Parent.Invetory

UIS.InputBegan:Connect(function(input) -- Enables GUI
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E and GUI.Enabled == false then
			GUI.Enabled = true
			print("Enabled")
			return GUI
		end
	end
end)

UIS.InputBegan:Connect(function(input) -- Should disable GUI but it doesnt
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			if GUI.Enabled == true and input.KeyCode == Enum.KeyCode.E then
				GUI.Enabled = false
				print("Disabled")
				return GUI
			end
		end
	end
end)
1 Like

Maybe this will work?

local GUI = script.Parent.Parent.Invetory

UIS.InputBegan:Connect(function(input) -- Enables GUI
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			if GUI.Enabled == false then
				GUI.Enabled = true
				print("Enabled")
				return GUI
			elseif GUI.Enabled == true then
				GUI.Enabled = false
				print("Disabled")
				return GUI
			end
		end
	end
end)

it works thanks for the help i appriciate it

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.