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

How would I make this script toggle the GUI?

function C(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		script.Parent.Parent.Classes.Backing.Visible = true
		print("C")
	else
		if script.Parent.Backing.Visible == true then
			script.Parent.Parent.Classes.Backing.Visible = false
		end
	end
end

game.ContextActionService:BindActionToInputTypes("keyPress", C, false, Enum.KeyCode.C)

When I press the letter C the GUI pops up but then it closes instantly. How would I toggle the GUI so that when I press it the GUI stays up and if I press C when the GUI is up the GUI will Close?

1 answer

✓ Accepted answer

KeyDown alternative;

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local back = script.Parent.Parent.Classes.:FindFirstChild('Backing')

mouse.KeyDown:connect(function(key)
	if key:lower() == 'c' then
		back.Visible = not back.Visible
	end
end)

3 comments

0

the 7th line has an error after you remove the dot on line 3 because the dot in not needed

0

fixed

0

Thx

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