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?
01 | while 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 ) |
I can just do that but I think there is a easier way!
Yes you are correct, there is an easier way.
1 | for i = 1 , 10 do |
2 | script.Parent.Transparency = script.Parent.Transparency + 0.1 |
3 | wait( 1.5 ) |
4 | end |
If you want it looped it would be...
01 | while 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 |
11 | end |
Helpful Link: http://robloxdev.com/articles/Roblox-Coding-Basics-Loops#For
Use for loop.
1 | for i = 0 , 1 , 0.1 do |
2 | wait() |
3 | script.Parent.Transparency = i |
4 | end |
Just like that. 0.1, is the increment of the transparency.
You can use for loops:
1 | for i = 0 , 1 , 0.1 do |
2 | script.Parent.Transparency = i |
3 | wait( 1.5 ) |
4 | 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
1 | for loop = 1 , 10 do |
2 | wait() |
3 | script.Parent.Transparency = loop/ 10 |
4 | end |
If you're trying to loop a particle emitter transparency, look into "NumberSequence".