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).