I’m currently trying to figure out the best way to achieve a part image, and light changing system.
My current idea is when an attribute changes, the folder that matches the said attribute will change their all of the children in the folder. (Some are lighting, some are images) I want to do this on the client, and I’m unsure of the best way to achieve this.
(There are about 20 folders)
Would a bunch of coroutines be a good way to handle the change signal for each attribute?
Instance:GetAttributeChangedSignal("AttributeName"):Connect(function()
-- Do stuff with the new value
end)
A bunch of coroutines constantly checking if a change happened is really inefficient. There’s always a way to connect the script that needs to change something directly with the function that handles the change.
That would work yes, but there are about 20 folders, so I would have too use 20 GetAttributeChanged with color changers, would it be a good idea to run those all in the same script? (20 of those)
This might look a bit messy, and I hate using a for loop within a for loop.
But here’s how it might look (group all the folders into a folder)
for _, folder in ipairs(mainFolder:GetChildren()) do
for _, child in ipairs(folder:GetChildren()) do
child:GetAttributeChangedSignal("AttributeName"):Connect(function()
--do stuff
end)
end
end
Alternatively, you could use 20 for loops (one for each folder).
GetAttributeChanged signals do not affect performance in any meaningful way.
If worried about organization there seems to be a simple loop solution you can use similar to what @12345koip said.
A bit modified from post above
If you want to organize it further, you could pack this away inside a modulescript sometimes heavy visual effects result in some messy looking code and the best answer is to hide it.