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,
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
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