Grave all parts with same name (What did I do wrong?)

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

Help!!!

1 Like

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.

1 Like

You are only changing the transparency of one part at a time.

1 Like

I have made a solution! Thanks for all the help!

Here’s the final code:

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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.