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

I do not know what has gotten into me with for loops can someone help?

Asked by 8 years ago

Well, I used to know for loops I guess? I tried scripting a for loop today to make a Part transparent it goes transparent by 0.1 at a time but stays transparent does not repeat to 0?

for i = 0, 1, 0.1 do 
    script.Parent.Transparency = i
    wait(0.5)
end

2 answers

Log in to vote
0
Answered by
LevelKap 114
8 years ago

you told the loop, to start at 0, end at 1, and go by an increment of 0.1 Of course it won't go back to zero because you told it to stop once it ends at 1.

Ad
Log in to vote
0
Answered by
KoreanBBQ 301 Moderation Voter
8 years ago

Yeah obviously, because it only runs once, and when it finishes gradually turning it to transparency 1, it stops.

You should use a while true do loop, that keeps running as long as the script is active, and make it go visible agian, like so:

while true do
    for i = 0, 1, 0.1 do 
        script.Parent.Transparency = i
        wait(0.5)
    end
    for i = 0, -1, -0.1 do 
        script.Parent.Transparency = i
        wait(0.5)
    end
end

Answer this question