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

How do you get the name of any gui by clicking it with the mouse?

Asked by 7 years ago

I know by getting the player's mouse you can click on a "BasePart" class, and get the information via using Target after getting the mouse. But how do you get Gui classes by clicking them with the mouse?

1 answer

Log in to vote
0
Answered by 7 years ago

You're asking a very vague question. To my understanding, your question is revolving around a gui being clicked. Some GUIs on ROBLOX have a property that allows them to be selected, such such a TextButton. Inside of those GUIs, there are usually local scripts that fire when the local player clicks them.

function onClick()
    --Execute code
end

script.Parent.MouseButton1Click:Connect(onClick)

In that manner, I guess you can make it print the name of the script's Parent lol. Another interpretation of your question is: "Using a single script, how do I get to know when a button is clicked?" -- I've done things like that before, but it's normally when all the buttons have the same "Parent" because that makes things easier. You will first loop the script into all the children, then tie a function when they're clicked. Here's a quick one I'll make:

local PARENTOFALL = script.Parent
for i, child in pairs (PARENTOFALL:GetChildren()) do
    if child.ClassName == ("ImageButton") or child.ClassName == ("TextButton") then-- adjust this if you want
        child.MouseButton1Down:Connect(function()
            print(child.Name)
        end)
    end
end

I just made this code so it might have a small typo of some sort, but I hope you get the idea. You're meant to loop the local script into all the buttons, then have a code doing whatever, using the buttons name's.. Your question is very vague but I hope I helped a bit!

0
Yes this works, thank you. Sorry for being so vague I am very new to both this form and Roblox Lua. I'll try to be more specific next time. purebrute 2 — 7y
0
It's alright, people only get better by asking iamnoamesa 674 — 7y
Ad

Answer this question