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

How do you determine what button the mouse clicked?

Asked by
0te 35
3 years ago

Hello,

UserInputService.InputBegan:connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then

I am trying to write if the mouse has clicked a button called ("button1") then but I am unsure on how to write it in terms of lua.

0
You could just use a ClickDetector if your button is a part. Or get the Event MouseButton1Click or Activated if it's a GUIButton. No need to get the mouse Spjureeedd 385 — 3y
0
Yes. I was going to do it script.Parent.MouseButton1Click:connect(function() instead but I've been told that userinputservice is always better. I don't know how it could work for this application though. 0te 35 — 3y
0
No if you were to click a button, like a GUI then I would say you should use MouseButton1Click or Activated Spjureeedd 385 — 3y
0
Okay, will do. Thank you 0te 35 — 3y
0
No problem Spjureeedd 385 — 3y

1 answer

Log in to vote
0
Answered by
2Loos 168
3 years ago

Use MouseButton1Click when trying to detect left-click on a GUI. Use MouseButton2Click when trying to detect right-click on a GUI.

For example:

--For local script under a TextButton.
script.Parent.MouseButton1Click:Connect(function()
    print("Parent was clicked.")
end)
Ad

Answer this question