Im creating an new effect frame by using :Clone() method for “effect” frame, and turn off “default” attribute in it.
So, when I need to refresh the list of the effects and add a new effect, or delete previous I need to cycle through children loop of “effectFrame” and check: If attribute “default” == false. And here is the question: Can I optimize that cycle to not to check attribute at every cycle and just cycle through it and delete unused frames. Maybe I have other way to combine that “I mustn’t check that objects” and “I must check that objects” in one folder in “effectFrame”? Or, somehow, I need to divide logic of placing objects on the start.
I thought about coping objects, that I dont wanna to check for deleting, and then delete every children and past them back with new effects, but I think that will take more time then my script.
Picture of my hierarchy
Here is the code:
UI.TickForEffects = function(character)
local statusbar = character:FindFirstChild("StatusBar")
if statusbar then
local effectFrame = statusbar:FindFirstChild("effectFrame")
if effectFrame then
for _, v in pairs(effectFrame:GetChildren()) do
if v:GetAttribute("default") == false then
v.duration.Value -= 1
print(v.duration.Value, v.duration.Value <= 0)
if v.duration.Value <= 0 then
v:Destroy()
end
end
end
else
warn("No effect frame provided for: ", character)
end
else
warn("No StatusBar provided for: ", character)
end
end