So I’ve got this menu with a couple for textButtons, I feel like it’d be impractical to write an event for literally every button.
Instead of doing something like:
I’d suggest creating a function so you can catch any new buttons added and run this function through the buttons that do exist. This way, you cover for an undefined amount of buttons if they aren’t all added at a single time. It also ticks off the rest of your use cases.
local function exampleFunction(parameters)
something(parameters)
end
scrollingFrame.ChildAdded:Connect(function (child)
if child:IsA("TextButton") then
child.MouseButton1Down:Connect(exampleFunction)
end
end)
for _, button in pairs(scrollingFrame:GetChildren()) do
if button:IsA("TextButton") then
button.MouseButton1Down:Connect(exampleFunction)
end
end
Funny enough, this tells the in pairs loop to run even tough the event is inside of it. I’ve been using this for quite a while and still can’t figure out the logic behind it xd