How would I shorten this script?
01 | script.Parent.BlackScreen.BackgroundTransparency = 0.1 |
02 | wait( 0.1 ) |
03 | script.Parent.BlackScreen.BackgroundTransparency = 0.2 |
04 | wait( 0.1 ) |
05 | script.Parent.BlackScreen.BackgroundTransparency = 0.3 |
06 | wait( 0.1 ) |
07 | script.Parent.BlackScreen.BackgroundTransparency = 0.4 |
08 | wait( 0.1 ) |
09 | script.Parent.BlackScreen.BackgroundTransparency = 0.5 |
10 | wait( 0.1 ) |
11 | script.Parent.BlackScreen.BackgroundTransparency = 0.6 |
12 | wait( 0.1 ) |
13 | script.Parent.BlackScreen.BackgroundTransparency = 0.7 |
14 | wait( 0.1 ) |
15 | script.Parent.BlackScreen.BackgroundTransparency = 0.8 |
16 | wait( 0.1 ) |
17 | script.Parent.BlackScreen.BackgroundTransparency = 0.9 |
18 | wait( 0.1 ) |
19 | script.Parent.BlackScreen.BackgroundTransparency = 1 |
A for loop
. Go to this link for help on what they are.
This code will work:
1 | for i = 1 , 10 do |
2 | script.Parent.BlackScreen.BackgroundTransparency = 0.1 * i |
3 | wait( 0.1 ) |
4 | end |
You can use a numerical for loop
like so:
1 | local blackScreen = script.Parent.BlackScreen; -- Create a reference to the GUIObject |
2 | for i = 0.1 , 1 , 0.1 do -- Start at 0.1, finish at 1, increase i by 0.1 every iteration |
3 | blackScreen.BackgroundTransparency = i; -- Se the property to whatever I equals |
4 | wait( 0.1 ); |
5 | end |
By using a for
loop to increase the transparency (Sorry if script didn't work);
1 | for i = 1 , 0 , 0.1 do --Heres our four loop |
2 | script.Parent.BlackScreen.BackgroundTransparency = i --There is where 'i' will come in |
3 | wait( 0.1 ) --Will wait each 0.10 milliseconds |
4 | end --The end to end the `for` loop code |
Hope this helped!