So... I made this script to dim lights that are all together in a folder. I want to dim all the lights at the same time (making them invisible, so a non-neon duplication of the lights becomes visible), but for some reason, the script dims one light at a time. Could somebody help me with this?
This is my script:
for name, child in pairs(script.Parent.Parent.Preps.L:GetChildren()) do if child:IsA("BasePart") then local value = 0 for i = 1, 20 do value = value + 0.05 child.Transparency = value wait(0.05) end end end
You will need to put the find children inside the for loop for transparency so it does them all at once:
local value = 0 for i = 1, 20 do value = value + 0.05 for name, child in pairs(script.Parent.Parent.Preps.L:GetChildren()) do if child:IsA("BasePart") then child.Transparency = value end end end
This will loop through the transparency but inside of the transparency loop it will go through all the children then change transparency then repeat until its done.
you can use coroutine.wrap(function()
to dim out all the lights without yielding. a numeric for loop
yields so it stops the script until it breaks or finishes. Just a reminder but you dont need to use a variable for the part's transparency to set to, just use the value.
for name, child in pairs(script.Parent.Parent.Preps.L:GetChildren()) do if child:IsA("BasePart") then local dimlights = coroutine.wrap(function() for i = 0,1,0.05 do child.Transparency = i wait(0.05) end end) dimlights() end end