PointerAction event on GuiObject is impossible, but I need it

Most input events in UserInputService also exist in GuiObject , except for UserInputService.PointerAction

Does anyone here know how to implement the UserInputService’s PointerAction event on a GuiObject?
The PointerAction event is essential for camera rotation using a mouse and touchpad.
You might say to retrieve PointerAction’s wheel, pan, and pinch from the InputObject’s Position, but they aren’t the same

UserInputService.PointerAction:Connect(function(wheel, pan, pinch, gpe) 
  print(
    `wheel: {wheel}\n`
  ) 
end)

UserInputService.InputChanged:Connect(function(input) 
  if input.UserInputType ~= Enum.UserInputType.MouseWheel then 
    return 
  end 
  print(`wheel position: {input.Position.Z}`) 
end)
wheel position: 1
wheel: 0.5

wheel position: -1
wheel: -0.5

wheel position: -1
wheel: -1

wheel position: -1
wheel: -1.5

wheel position: 1
wheel: 0.5

wheel position: 1
wheel: 0.5

wheel position: 1
wheel: 0.5

How can I implement a PointerAction event on a GuiObject?

1 Like

Implement with the context of yours :

local UserInputService = game:GetService("UserInputService")
local GuiObject = script.Parent:WaitForChild("YourGuiObject") -- Replace with your actual GuiObject

-- Function to check if a point is within the GuiObject bounds
local function isPointInGuiObject(guiObject, point)
    local absPos = guiObject.AbsolutePosition
    local absSize = guiObject.AbsoluteSize
    return point.X >= absPos.X and point.X <= absPos.X + absSize.X and point.Y >= absPos.Y and point.Y <= absPos.Y + absSize.Y
end

-- Capture PointerAction events
UserInputService.PointerAction:Connect(function(wheel, pan, pinch, gpe)
    -- Check if the pointer is over the GuiObject
    local mousePosition = UserInputService:GetMouseLocation()
    if isPointInGuiObject(GuiObject, mousePosition) then
        -- Fire a custom event or handle the action in the context of the GuiObject
        print(`PointerAction on GuiObject - wheel: {wheel}, pan: {pan}, pinch: {pinch}, gpe: {gpe}`)
        -- Your custom handling logic here
    end
end)

-- Capture MouseWheel events as a fallback or additional functionality
UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseWheel then
        local mousePosition = UserInputService:GetMouseLocation()
        if isPointInGuiObject(GuiObject, mousePosition) then
            print(`MouseWheel on GuiObject - wheel position: {input.Position.Z}`)
            -- Your custom handling logic here
        end
    end
end)
1 Like

It’s cool and I can implement it in the Roblox client. Thank you so much :D

But there is a problem, it can’t be implemented on plugin widgets :(

1 Like