Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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?

0
Do you want all of them to change at the same time? GoldenPhysics 474 — 10y
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. alphawolvess 1784 — 10y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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
Ad

Answer this question