Hello i need help with a context ActionService Script
i need to make it like when you press “B” button gui will disappear and when you press it again it will appear
but for some reason when you unholding B button function starts again and gui appear how do i disable that?
local ContextActionService = game:GetService("ContextActionService")
local DeBounce = true
local function buttonpressed()
local User = game.Players.LocalPlayer
if DeBounce == true then
DeBounce = false
game.Players:FindFirstChild(User.Name).PlayerGui.Disguise.Enabled = false
elseif DeBounce == false then
DeBounce = true
game.Players:FindFirstChild(User.Name).PlayerGui.Disguise.Enabled = true
end
end
ContextActionService:BindAction("MakeGuiAppearAndDisappear", buttonpressed, true, "b")
ContextActionService:SetPosition("MakeGuiAppearAndDisappear", UDim2.fromScale(-0.1,-0.2))
Thanks for trying to help 
ContextActionService returns 3 arguments into a function: actionName, inputState, and inputObject. To disable this, use inputState in an if statement.
local function buttonpressed(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
– Your code
end
end
Hope this helps 
2 Likes
like that?
local ContextActionService = game:GetService("ContextActionService")
local DeBounce = true
local function buttonpressed(actionName, inputState, inputObject)
local User = game.Players.LocalPlayer
if inputState.Begin then
if DeBounce == true then
DeBounce = false
game.Players:FindFirstChild(User.Name).PlayerGui.Disguise.Enabled = false
elseif DeBounce == false then
DeBounce = true
game.Players:FindFirstChild(User.Name).PlayerGui.Disguise.Enabled = true
end
end
end
ContextActionService:BindAction("MakeGuiAppearAndDisappear", buttonpressed, true, "b")
ContextActionService:SetPosition("MakeGuiAppearAndDisappear", UDim2.fromScale(-0.05,-0.05))
oh wait i messed up here
yeah its worked, thanks you very much!