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

How would I shorten this?

Asked by 10 years ago

How would I shorten this script?

01script.Parent.BlackScreen.BackgroundTransparency = 0.1
02wait(0.1)
03script.Parent.BlackScreen.BackgroundTransparency = 0.2
04wait(0.1)
05script.Parent.BlackScreen.BackgroundTransparency = 0.3
06wait(0.1)
07script.Parent.BlackScreen.BackgroundTransparency = 0.4
08wait(0.1)
09script.Parent.BlackScreen.BackgroundTransparency = 0.5
10wait(0.1)
11script.Parent.BlackScreen.BackgroundTransparency = 0.6
12wait(0.1)
13script.Parent.BlackScreen.BackgroundTransparency = 0.7
14wait(0.1)
15script.Parent.BlackScreen.BackgroundTransparency = 0.8
16wait(0.1)
17script.Parent.BlackScreen.BackgroundTransparency = 0.9
18wait(0.1)
19script.Parent.BlackScreen.BackgroundTransparency = 1   

3 answers

Log in to vote
2
Answered by 10 years ago

A for loop. Go to this link for help on what they are.

This code will work:

1for i=1,10 do
2    script.Parent.BlackScreen.BackgroundTransparency = 0.1 * i
3    wait(0.1)
4end
Ad
Log in to vote
1
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
10 years ago

You can use a numerical for loop like so:

1local blackScreen = script.Parent.BlackScreen; -- Create a reference to the GUIObject
2for 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);
5end
Log in to vote
1
Answered by 10 years ago

By using a for loop to increase the transparency (Sorry if script didn't work);

1for i = 1, 0, 0.1 do --Heres our four loop
2script.Parent.BlackScreen.BackgroundTransparency = i --There is where 'i' will come in
3wait(0.1) --Will wait each 0.10 milliseconds
4end --The end to end the `for` loop code

Hope this helped!

0
It should be 0, 1. It's start, end [, increment] and 100 milliseconds, not 0.1 milliseconds jakedies 315 — 10y

Answer this question