Still have questions? Join our Discord server and get real time help.
Log in to vote

How to use the ContextActionService for Open/Close GUI?

Asked by 2 years ago
Edited 2 years ago
local CAS = game:GetService("ContextActionService")
local repStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local frame = player:WaitForChild("PlayerGui"):WaitForChild("Menu").Main
local open = false

local function openMenu(action, inputState, obj)
    if inputState == Enum.UserInputState.Begin then
        frame:TweenPosition(,0,0.5,0), "Out", "Quint")
    if obj.KeyCode == Enum.KeyCode.G then
        frame:TweenPosition(,0,-1,0), "In", "Quint")

CAS:BindAction("openMenu", openMenu, false, Enum.KeyCode.G)

How do I make it just a single press 'G' to control open and close Gui instead of holding 'G' to open the Gui and releases 'G' to close the Gui and why if I resets my player I get an error saying "Can only tween objects in the workspace"

Answer this question