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

Menu not opening after pressing m using userinput?

-- Varibles

local UIS = game:GetService("UserInputService")

--[[

UI Varibles

--]]

local Title = script.Parent.Title

local Backframe = script.Parent.BackFrame

local IsActive = false

local function OpenMenu()
	if IsActive == false then
		IsActive = true
		Title.Visible = true
		Backframe.Visible = true
	elseif IsActive == true then
		IsActive = false
		Title.Visible = false
		Backframe.Visible = false
	end
end

UIS.InputBegan:Connect(function(input,IsTyping)
	if IsTyping then
		return
	elseif input.UserInputType == Enum.KeyCode.M then
		OpenMenu()
	end
end)

Get no output error so idk what to tell u

1 comment

0

There is no need to evaluate another term in your conditional, you can simply use an else clause as the only other state "IsActive" could be in is true.

1 answer

✓ Accepted answer

If you had read up on the documentation for UserInputService's UserInputType property, you would've recognized that its purpose is to describe the type of Input being received; most Enums are organized to be compaired with an identical property name, which is also another indicator of a conflicting expression.

You're looking for the KeyCode property of InputObject:

local UserInputService = game:GetService("UserInputService")


UserInputService.InputBegan:Connect(function(InputObject, GameProcessedInput)
	if (GameProcessedInput) then return end
	---------------
	if (InputObject.KeyCode == Enum.KeyCode.M) then
		print("Pressed M!")
	end
end)

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