Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me with 2 for loops not repeating?

I have a brick I want to go from almost 0 transparent to almost .8 in transparency over and over, can anyone help?

while true do
   for i = 0, .8, .01 do
	script.Parent.Transparency = i
	wait(.05)
    for i = .8, 0, .01 do
	script.Parent.Transparency = i
	wait(.05)
end
end
end

1 answer

Tab your code properly. That is vital for you to become a good scripter!

while true do
	for i = 0, .8, .01 do
		script.Parent.Transparency = i
		wait(.05)
		for i = .8, 0, .01 do
			script.Parent.Transparency = i
			wait(.05)
		end
	end
end

Notice how you have the second for loop inside the first one? That's not right -- you want the second one to happen after, not during it.

while true do
	for i = 0, .8, .01 do
		script.Parent.Transparency = i
		wait(.05)
	end
	for i = .8, 0, .01 do
		script.Parent.Transparency = i
		wait(.05)
	end
end

Now the first for loop will work as expected, but the second won't; .8 is larger than 0, but you're telling it to go up (+.01). You need to tell it to go down by giving a negative step:

while true do
	for i = 0, .8, .01 do
		script.Parent.Transparency = i
		wait(.05)
	end
	for i = .8, 0, -.01 do
		script.Parent.Transparency = i
		wait(.05)
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.