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

How do you get the Gui that the mouse clicked? [NOT SOLVED YET]

Asked by 10 years ago

So, I'm making a game, and I need to know how to get the Gui that the mouse clicked. Like, say I wanted to get the name of the object that I clicked. How would I get to the Gui that I clicked? Please help.

2 answers

Log in to vote
1
Answered by 10 years ago

script.Parent.MouseButton1Down:connect(function(click)

This includes the connect as well.

See where it says "script.Parent"? Direct that to the button you want to script.

Example: You have 3 buttons. One, two and three. The script has the exact same parent as the buttons, but you only want it to activate when you click button one. You do: script.Parent.one.MouseButton1Down:connect(function(click)

Hope this helps.

0
No, but I mean, is there a way you could access all of them from one script, that's not put inside any of the Guis? ImmenseKassing 120 — 10y
Ad
Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

You don't get the button through the mouse, you get the mouse through the button. TextButton

Example:

-- StarterGui
--  ScreenGui
--      Frame
--          TextButton
--              Script

local btn = script.Parent

btn.MouseButton1Click:connect(function()
    print(btn:GetFullName() .. " was clicked.")
end)

Answer this question