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?

    script.Parent.BlackScreen.BackgroundTransparency = 0.1
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.2
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.3
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.4
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.5
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.6
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.7
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.8
    wait(0.1)
    script.Parent.BlackScreen.BackgroundTransparency = 0.9
    wait(0.1)
    script.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:

for i=1,10 do
    script.Parent.BlackScreen.BackgroundTransparency = 0.1 * i
    wait(0.1)
end
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:

local blackScreen = script.Parent.BlackScreen; -- Create a reference to the GUIObject
for i = 0.1, 1, 0.1 do -- Start at 0.1, finish at 1, increase i by 0.1 every iteration
    blackScreen.BackgroundTransparency = i; -- Se the property to whatever I equals
    wait(0.1);
end
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);

for i = 1, 0, 0.1 do --Heres our four loop
script.Parent.BlackScreen.BackgroundTransparency = i --There is where 'i' will come in
wait(0.1) --Will wait each 0.10 milliseconds
end --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