Hello,
I am trying to create a gui that will be opened and closed via a single key, say, the 'o' key. I have created a toggle function but it doesn't work as expected. The window only toggles (closed) if I HOLD DOWN the key. I have even tried an intermediate variable to hold the state, but to no effect. Could someone explain what I have missed or done incorrectly?
If I create separate key bindings for open and close, it works fine. Any assistance would be greatly appreciated.
local CAS = game:GetService("ContextActionService")
local cmdFrame = script.Parent.cmdFrame
local isOpen = false
local function make_visible()
cmdFrame.Visible = true
end
local function make_invisible()
cmdFrame.Visible = false
end
local function toggle_frame()
if isOpen then
cmdFrame.Visible = false
else
cmdFrame.Visible = true
end
isOpen = not isOpen
end
CAS:BindAction("OpenCmdFrame",toggle_frame,true,Enum.KeyCode.O)
--CAS:BindAction("CloseCmdFrame",make_invisible,true,Enum.KeyCode.P)

1 comment
oh wow. i never knew you could do that!