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
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
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
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!