Need help with a lever-like function

I want one of my function to act like a lever, you press a button something happens, you press it again and the thing goes away. Basically, I want to find a way to be able to press a button and have one of 2 things happen depending on if you have already pressed the button or not. For example, I press M to make a menu appear, I press M again to make it go away. I’ve tried finding specific tutorials to no avail.

What do I have to change in this code to accomplish my goal?

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		menu.BackgroundTransparency = 0
	end
end)
local menuVisible = true

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		if menuVisible == true then
			menu.BackgroundTransparency = 1 -- Make menu disappear
		else
			menu.BackgroundTransparency = 0 -- Make menu appear
		end
	end
end)

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