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

Is there another way to do loop this transparency?

Asked by 6 years ago

I write a command about transparency, but I want to loop it, I knew how to, but I kind of forget, I remember it's like "for i" something like, so can anyone help me remember?

while true do
    script.Parent.Transparency = 0.1
    wait(1.5)
    script.Parent.Transparency = 0.2
    wait(1.5)
    script.Parent.Transparency = 0.3
    wait(1.5)
    script.Parent.Transparency = 0.4
    wait(1.5)
    script.Parent.Transparency = 0.5
    wait(1.5)
    script.Parent.Transparency = 0.6
    wait(1.5)
    script.Parent.Transparency = 0.7
    wait(1.5)
    script.Parent.Transparency = 0.8
    wait(1.5)
    script.Parent.Transparency = 0.9
    wait(1.5)
    script.Parent.Transparency = 1
end

I can just do that but I think there is a easier way!

4 answers

Log in to vote
0
Answered by 6 years ago

Yes you are correct, there is an easier way.

for i = 1,10 do
    script.Parent.Transparency = script.Parent.Transparency + 0.1
    wait(1.5)
end

If you want it looped it would be...

while true do
    for i = 1,10 do
        script.Parent.Transparency = script.Parent.Transparency + 0.1
        wait(1.5)
    end

    for i = 1,10 do
        script.Parent.Transparency = script.Parent.Transparency - 0.1
        wait(1.5)
    end
end

Helpful Link: http://robloxdev.com/articles/Roblox-Coding-Basics-Loops#For

0
XxxLloyd061302xxX's answer is probably better in terms of changing the transparency though. climethestair 1663 — 6y
0
XxxLloyd061302xxX doesnt make his own scripts, he copies other peoples scripts and makes them into his video tutorial. User#23365 30 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

Use for loop.


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

Just like that. 0.1, is the increment of the transparency.

0
thank you so much for reminding me! tysm! RainbowBeastYT 85 — 6y
Log in to vote
0
Answered by 6 years ago

You can use for loops:

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

Or, you can use TweenServices, which are a bit more complicated, but are easy to understand nonetheless:

https://wiki.roblox.com/index.php?title=API:Class/TweenService/Create

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
for loop = 1,10 do
    wait()
    script.Parent.Transparency = loop/10
end

If you're trying to loop a particle emitter transparency, look into "NumberSequence".

Answer this question