MouseButton1 callback Not Firing

I’m trying to use ContextActionService to bind callbacks for when a player releases a mouse button for controlling UI elements, such as a slider. However, I have noticed that my function tied to MouseButton1 isn’t be called when the mouse is over a UI element (it works perfectly when I move the mouse out of the Frame).

I already tried using BindActionAtPriority (seen below), but that didn’t seem to help. Anyone run into this issue?

ContextActionService:BindActionAtPriority("CancelTune", function(actionName, inputState, inputObj)
        self:EndDrag_CAS(actionName, inputState, inputObj)
	end,
	false, Enum.ContextActionPriority.High.Value, Enum.UserInputType.MouseButton1)

try incrementing Enum.ContextActionPriority.High.Value by 1.

No dice (I cranked it up to 10000 too). It looks more specifically to only not fire when I’m hovered over buttons. Still not sure why it wouldn’t fire.

This is a problem with the Roblox API, and is an unfortunate limitation.

I think I ran into this exact same problem and I believe the solution was toggling the Modal property. Will double check what I did though

Edit:

Nvm, was unable to get this to work with ContextActionService and had to resort to UserInputService as it allowed me to ignore whether the engine handled it or not through the gameProcessedEvent parameter.

I was able to replicate the issue when the mouse is hovering over a TextButton, but when the mouse was hovering over the Frame itself, the bound function was called. Here’s the code I tested, for reference:

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")


local MouseButton1 = Enum.UserInputType.MouseButton1
local Priority = Enum.ContextActionPriority.High.Value

local function testFunction(actionName, inputState, inputObject)
	if inputState ~= Enum.UserInputState.End then
		return Enum.ContextActionResult.Pass
	end
	print(`Action [{actionName}] occurred. UserInputType was [{inputObject.UserInputType}].`)
	
	local x, y = inputObject.Position.X, inputObject.Position.Y
	local GuiObjects = PlayerGui:GetGuiObjectsAtPosition(x, y)
	
	warn(table.unpack(GuiObjects))
	
	return Enum.ContextActionResult.Sink
end

ContextActionService:BindActionAtPriority(
	"testActionName",
	testFunction,
	false,
	Priority,
	MouseButton1
)


UserInputService.InputEnded:Connect(function(inputObject)
	local userInputType = inputObject.UserInputType
	local userInputState = inputObject.UserInputState
	
	if userInputType ~= Enum.UserInputType.MouseButton1 then return end
	
	local x, y = inputObject.Position.X, inputObject.Position.Y
	local GuiObjects = PlayerGui:GetGuiObjectsAtPosition(x, y)
	
	if #GuiObjects >= 1 then
		print("UserInputService: "..tostring(table.unpack(GuiObjects)))
	end
	
	-- Testing to see if MouseButton1 was bound to any other action with a higher priority
	--warn(ContextActionService:GetAllBoundActionInfo())
end)

Unfortunately, after looking through the Roblox Creator Documentation page for the ContextActionService, I wasn’t able to find any info about this behavior nor was there another suitable method / event that seemed to be applicable for this specific use case.



After searching for related threads here on the Developer Forum, I found a feature request named “Touch Improvements for ContextActionService”, and one of the points that was mentioned was the following:

And when a staff member responded to the post, the first half of their response was the following:



With all of this in mind, it seems like there’s a high likelihood that ContextActionService currently isn’t viable for the use case of calling a bound function when listening for an existing GuiButton to be pressed with one of the mouse buttons. Maybe there is a proper solution out there that would still make use of the ContextActionService, but I’m not aware of one at the moment, unfortunately.

The only other alternative I can think of right now would be to utilize the UserInputService and check if InputObject.UserInputType matches Enum.UserInputType.MouseButton1 (similar to what I included at the end of the example code block earlier in this post).

Thank to everyone who replied, I also resorted back to the UserInputService approach to things. Unfortunate since it’s a perfect use case for ContextActionService binding/unbinding.

I am marking this reply as solution since I thought it to be most in-depth for anyone who has this problem in the future.

Edit: For those coming to this thread, this issue may have something to do with the Active property on some GUI elements, which sinks input when set to true

1 Like

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