Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make MouseClick Events work over Gui objects?

Asked by
Sulu710 142
3 years ago
Edited 3 years ago

I'm trying to make a camera pan script, and it all works great. The camera moves as the player moves their mouse across the screen. The problem is, when I'm hovering over a GUI object and let go of the mouse button 1, it doesn't register it because it's over a GUI object. So unless I click and unclick again it doesn't disengage from the panning state. And even this still breaks my script sometimes. Does anyone know of a way around this? I can provide my script if that helps:

local function Bind(actionName,inputState,inputObject)
    if inputState == Enum.UserInputState.Begin then
        print("Pressed down")
        if inputObject.UserInputType == Enum.UserInputType.Touch then
            connection2 = UserInputService.TouchMoved:Connect(MoveCamera())
        elseif inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            connection2 = Mouse.Move:Connect(function()
                MoveCamera({X = Mouse.X})
            end)
        end
    else
        connection2:Disconnect()
        print("Unpressed")
        startPos = nil
    end
end
ContextActionService:BindAction("PressedDown",Bind,false,Enum.UserInputType.MouseButton1,Enum.UserInputType.Touch)

This is the relevant part of the script. The script works great, except for when I let go of the mouse button over a gui object. Then it doesn't register the mouse button was released and it breaks my script. Any help would be greatly appreciated, thank you for reading!

Answer this question