I am trying to change the transparency of parts at a random speed but it isn’t even changing the parts!
What did I do wrong:
local Time = math.random(1,20) / 100
while wait() do
local Folder = workspace:WaitForChild("Lightning")
for i,v in pairs(Folder:GetDescendants()) do
if v.Name == "Part" then
while true do
v.Transparency = 1
wait(Time)
v.Transparency = 0
end
end
end
end
Be careful with this nested loop spam. Once your code reaches the while true loop that sets the Transparency, the code will be permanently stuck there, and will not go on to any other parts.
Also, you shouldn’t use wait; use task.wait, and also don’t put the wait call in your loop condition as it causes unneeded complexity.
local Time = math.random(1,20) / 100
while wait() do
local Folder = workspace:WaitForChild("Lightning")
for i,v in pairs(Folder:GetDescendants()) do
if v.Name == "Part" then
v.Transparency = 1
end
end
task.wait(Time)
for i,k in pairs(Folder:GetDescendants()) do
if k.Name == "Part" then
k.Transparency = 0
end
end
end