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

Cannot make my loop do what I want? [Solved]

I have 4 parts which are labeled in myTable. I'm trying to make them go up 0.1 every 0.2 seconds. Then I want my script to detect that a part has hit Transparency 1 and break it's loop and continue on to my next statement. This will basically do the same but opposite. (Starting from 1, it'll go down 0.1 every 0.2 seconds)

myTable = {game.Workspace.one,game.Workspace.two,game.Workspace.three,game.Workspace.four}

while true do
for i,v in pairs (myTable) do
	v.Transparency = v.Transparency + 0.1
	wait(0.2)
	if v.Transparency == 1 then
		break
	end	
		if v.Transparency == 1 then
			for i,v in pairs (myTable) do
				v.Transparency = v.Transparency - 0.1
				wait(0.2)
			end
		end 
	
end
end

Also, how would I make this stop at 0 transparency and do +0.1 and repeat this over and over? I can't figure it out. Do I need a whole new code?

2 comments

0

Do you want all of them to change at the same time?

0

No, I wanted it to go one then two, three, and four. Then repeat both functions Perci gave but I can probably edit some things along with his.

1 answer

✓ Accepted answer

The easiest way to accomplish this is to just use a numeric for loop. This will allow us to easily change the transparency and have no need for lots of if statements or breaks.

--Invisible
for i = 0, 1, 0.1 do
	wait(0.2)
	for _,v in pairs(myTable) do
		v.Transparency = i
	end
end

--Visible
for i = 1, 0, -0.1 do
	wait(0.2)
	for _,v in pairs(myTable) do
		v.Transparency = i
	end
end

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