Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make this script toggle the GUI?

Asked by 10 years ago
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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

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)
0
the 7th line has an error after you remove the dot on line 3 because the dot in not needed rabidhalofan12345 55 — 10y
0
fixed Goulstem 8144 — 10y
0
Thx rabidhalofan12345 55 — 10y
Ad

Answer this question