The Most Efficient Way To Create A Index GUI

Hello!

I am currently trying to make an index gui in game where when you click on the button, it shows you information about that certain location you discovered. The only problem is that I have to make around 40 of these, and I am wondering if there is a better way to do this then defining each and every one of the events/gui. Ex:

local Corruption = script.Parent:FindFirstChild("Corruption")

local CorruptionEvent = game.ReplicatedStorage:FindFirstChild("CorruptionEvent")

Corruption.MouseButton1Click:Connect(function() 
CorruptionEvent:FireServer()
end

And I would have to do this for ALL of them, which I think there has to be a better method to (aka soft coding it). Any help will be appreciated.
Thanks,

R3M1X

you can make a for loop to loop through all of the children of script.Parent

for i,v in ipairs(script.Parent:GetChildren()) do
     if v.ClassName == "Whatever class you need" then
          v.MouseButton1Click:Connect(function() 
                CorruptionEvent:FireServer()
          end)
     end
end

EDIT: you will probably need an if statement to check if the classname is the class you want so you dont try to do it to the script

1 Like

What does the classname print out? Does it print out the object’s name, the objects location (in the explorer), or something else?

ClassName is a property, for example a parts class name is “Part” and a text buttons classname is “TextButton” a frames class name is “Frame”

it’s basically just the name of the type of object, and it is a read only so it never changes

1 Like

Alright, thanks for informing me! I’ll use this in game. Thanks again!

R3M1X

1 Like