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 5 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 5 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 — 5y
0
XxxLloyd061302xxX doesnt make his own scripts, he copies other peoples scripts and makes them into his video tutorial. User#23365 30 — 5y
Ad
Log in to vote
1
Answered by 5 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 — 5y
Log in to vote
0
Answered by 5 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 5 years ago
Edited 5 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