Is calling functions for multiple GUIs by means of a for loop bad practice?

This is more of a theory question, but is what said in the title bad practice?

I know the title is a bit confusing, so here’s an example; say you want to perform a certain tween for a GUI object when it is hovered over. The most self-explanatory solution is to loop through all the objects using this:

for i, v in ipairs(GUIObject:GetChildren()) do
   v.MouseHoverEnter:Connect(function()
       -- Blah Blah Blah
   end)
end

Is this bad practice? Is there a better option? I have considered trying OOP for the first time, but it seems not great since I have a lot of different GUI objects that have different needs, and making a ton of classes seems kind of tedious. I have heard about subclasses, but I have no idea how to implement this. Thanks!

As long as you are not overdoing it/putting too much logic into the function, I think you should be fine.

1 Like

I wouldn’t say this is “bad practice”

1 Like

Whew, that’s a relief :sweat_smile:.

yea as long as you follow what @ElusiveEpix said, you should be fine :smiley:

1 Like

Not exactly a bad practice. I think I have found GUI code containing initialization that performs these lines in some similarity.

1 Like