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

Way to detect mouse click over certain GUI objects?

Asked by
LuaQuest 450 Moderation Voter
8 years ago

So I'm trying to detect when the mouse is clicked every time, but certain GUI objects like TextButtons and TextBoxs get in the way of this. I tried using UserInputService, but apparently there's no registered key for mouse inputs.

Is there any way of detecting when the mouse is clicked, even if it's being clicked over a TextButton or TextBox? Because apparently clicking either of these GUI objects hides the click event from Button1Down / Button1Up on the PlayerMouse.

If anyone could provide an example, or even determine whether it's possible or not, I'd really appreciate it.

1 answer

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
8 years ago

You were on the right track to start off with. All we need here is to use the UserInputService. I just tested it using the InputBeganevent, and it works fine.

All we need to do is get the UserInputService, then check when the event fires and see what type of input was used.


Here's an example code (In a LocalScript) :

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then --Checks to see if the input was the left mouse button
        print("The left mouse button was clicked!")
    end
end)

And there you go, it's as simple as that!


Anyways, I hope this helped. If you have any further problems/questions, please leave a comment below, and I'll see what I can do.

0
Thanks LuaQuest 450 — 8y
0
No problem, happy to help dyler3 1510 — 8y
Ad

Answer this question