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?

01while true do
02    script.Parent.Transparency = 0.1
03    wait(1.5)
04    script.Parent.Transparency = 0.2
05    wait(1.5)
06    script.Parent.Transparency = 0.3
07    wait(1.5)
08    script.Parent.Transparency = 0.4
09    wait(1.5)
10    script.Parent.Transparency = 0.5
11    wait(1.5)
12    script.Parent.Transparency = 0.6
13    wait(1.5)
14    script.Parent.Transparency = 0.7
15    wait(1.5)
View all 21 lines...

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.

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

If you want it looped it would be...

01while true do
02    for i = 1,10 do
03        script.Parent.Transparency = script.Parent.Transparency + 0.1
04        wait(1.5)
05    end
06 
07    for i = 1,10 do
08        script.Parent.Transparency = script.Parent.Transparency - 0.1
09        wait(1.5)
10    end
11end

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.

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

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:

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

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
1for loop = 1,10 do
2    wait()
3    script.Parent.Transparency = loop/10
4end

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

Answer this question