Context Action Service does something once and never again

It does open and never again

local function Menu(actionName, inputState, _inputObject)
	if actionName == "OpenMenu" then
		script.Parent.Enabled = true
		Services.CS:AddTag(Player.Player, "InMenu")
		Tweens.OpenTween:Play()
	elseif actionName == "CloseMenu" then
		Tweens.CloseTween:Play()
		Services.CS:RemoveTag(Player.Player, "InMenu")
		script.Parent.Enabled = false
	end
end

Services.UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end

	if input.KeyCode == Enum.KeyCode.M and Player.Player:HasTag("InMenu") then
		Services.CAS:BindActionAtPriority("CloseMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("close")
	elseif input.KeyCode == Enum.KeyCode.M and not Player.Player:HasTag("InMenu") then
		Services.CAS:BindActionAtPriority("OpenMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("open")
	end
end)

Have you tried unbinding the previous action before binding a new one?

local function Menu(actionName, inputState, _inputObject)
	if actionName == "OpenMenu" then
		script.Parent.Enabled = true
		Services.CS:AddTag(Player.Player, "InMenu")
		Tweens.OpenTween:Play()
	elseif actionName == "CloseMenu" then
		Tweens.CloseTween:Play()
		Services.CS:RemoveTag(Player.Player, "InMenu")
		script.Parent.Enabled = false
	end
end

local function BindActions()
	-- Unbind previous actions
	Services.CAS:UnbindAction("OpenMenu")
	Services.CAS:UnbindAction("CloseMenu")
	
	-- Bind new actions
	if Player.Player:HasTag("InMenu") then
		Services.CAS:BindActionAtPriority("CloseMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("close")
	else
		Services.CAS:BindActionAtPriority("OpenMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("open")
	end
end

BindActions()

Services.UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end
	
	if input.KeyCode == Enum.KeyCode.M then
		BindActions()
	end
end)

yeah, still doesn’t close for some reason

it just keeps sending open and not close

local function Menu(actionName, inputState, _inputObject)
	if actionName == "OpenMenu" then
		script.Parent.Enabled = true
		Services.CS:AddTag(Player.Player, "InMenu")
		Tweens.OpenTween:Play()
	elseif actionName == "CloseMenu" then
		Tweens.CloseTween:Play()
		Services.CS:RemoveTag(Player.Player, "InMenu")
		script.Parent.Enabled = false
	end
end

local function BindActions()
	if Player.Player:HasTag("InMenu") then
		Services.CAS:UnbindAction("OpenMenu")
		Services.CAS:BindActionAtPriority("CloseMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("close")
	else
		Services.CAS:UnbindAction("CloseMenu")
		Services.CAS:BindActionAtPriority("OpenMenu", Menu, true, 0, Enum.KeyCode.M)
		warn("open")
	end
end

BindActions()

Services.UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end

	if input.KeyCode == Enum.KeyCode.M then
		BindActions()
	end
end)

Can you try this?

same problem as before (character minimum)

1 Like

Alright so I have tried following the issue, and I noticed that the menu function never receives the “CloseMenu” action name. (EDIT: It has something to do with the Tags)

2 Likes

It was because theyre on the same button

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.