Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

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?

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.