ContextActionService not firing when mouse input ends over a UI

The problem in facing is that whenever I hold down my MouseButton1 normally then I move my mouse over to a UI or press escape, it does not fire a signal to stop filling up the Bar.

This is the portion of the script that is bugged right now:

ContextActionService:BindAction(M1_ActionName,function(ActionName: string, InputState: Enum.UserInputState, InputObject: InputObject)
		--Guard
		if ActionName ~= M1_ActionName then
			return
		end
		
		if InputState == Enum.UserInputState.Begin then
			FillPowerBar(true, 5)
		else
			FillPowerBar(false)
		end
	end,false, Enum.UserInputType.MouseButton1)

1 Like

I remember having a similar problem a few years ago. What I did was basically made the script only listen for a userInput Ended event instead of a contextAction.

On the side note, I never found a reliable solution for making inputs not sink when your mouse is over a ui. I’d just recommend you turn interactable and active off on every non essential ui.

like so:

ui.Active = false
ui.Interactable = false
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local GuiService = game:GetService("GuiService")

ContextActionService:BindAction(
	M1_ActionName,
	function(ActionName, InputState, InputObject)
		if ActionName ~= M1_ActionName then
			return
		end

		if InputState == Enum.UserInputState.Begin then
			FillPowerBar(true, 5)
		end
	end,
	false,
	Enum.UserInputType.MouseButton1
)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		FillPowerBar(false)
	end
end)

-- This should fix your escape menu thing
game.GuiService.MenuOpened:Connect(function()
	FillPowerBar(false)
end)
1 Like