Key to open gui

So I made a ui where if you select a weapon the entire ui turns invisible and you can only get the ui back by pressing a key but thats where the problem starts. The ui won’t come back. Can anyone tell me what is wrong with this script?

local menu = script.Parent.Menu

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(keyCode)
	if keyCode.keycode == Enum.KeyCode.M and menu.Visible == false then
		menu.Visible = true
	end
end)
2 Likes

Instead of keyCode.keycode, do keycode.KeyCode.

3 Likes

You should try:

local menu = script.Parent.Menu

local UserInputService = game:GetService(“UserInputService”)

UserInputService.InputBegan:Connect(function(keyCode)
if keyCode.KeyCode == Enum.KeyCode.M then
menu.Visible = not menu.Visible
end
end)