Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make this script shorter? (LocalScript)

How do i make this script shorter? (its parent is in a TextLabel) This is the script :

----this is fade in---
local debounce = .1 --put number here
local bTrans = script.Parent.BackgroundTransparency
local tTrans = script.Parent.TextTransparency
bTrans = .9
tTrans = .9
wait(debounce)
bTrans = .8 
tTrans = .8
wait(debounce)
bTrans = .7
tTrans = .7
wait(debounce)
bTrans = .6
tTrans = .6
wait(debounce)
bTrans = .5
tTrans = .5
wait(debounce)
bTrans = .4
tTrans = .4
wait(debounce)
bTrans = .3
tTrans = .3
wait(debounce)
bTrans = .2
tTrans = .2
wait(debounce)
bTrans = .1
tTrans = .1
wait(debounce)
bTrans = 0
tTrans = 0
wait(debounce)

If you answer this correctly i will mark it as a answer.

2 answers

✓ Accepted answer

You Can Use Something Called for i loops which can loop through or "repeat" things in quick sucsession !

Instead of typing out the transparency fade line by line , you can use a for i Loop to make things shorter !

here is an example of what I mean !

for i = 1 , 10 , 1 do---Will Start at Number 1 and Will Loop And Repeat This Section of Code 10 Times ! 
wait(debounce)

bTrans = bTrans - .1
tTrans = tTrans - .1

end

This Will Loop or "Repeat" That Section of code 10 time starting from the number 1 you can see in for i = 1 , 10 , 1

The First Number is 1 and That Will Be Where the Number of Times Starts At

The Second Number 10 are the Number Of Times It Repeats

And The 3rd Number 1 Is The Increment of Every Loop

If The Incrament was 3 , I believe the code will only repeat 4 times as oppose to 10 because It will Go From 1 To 4 To 7 Then To 10

while going from 1 To 10 is ten times because It will Repeat The Code : 1 , 2 ,3 , 4 , 5 , 6 ,7 ,8 ,9 and 10 TImes !

Use a for loop.

Example:

local bTrans = script.Parent.BackgroundTransparency
local tTrans = script.Parent.TextTransparency

for i = 9,1,-1 do
	bTrans.Transparency = i/10
	tTrans.Transparency = i/10
	wait(0.1)
end

If you need more help, you should use the developer forum. Here's a link: https://developer.roblox.com/en-us/articles/Loops

This discussion is preserved as it was. New answers, comments, and votes are closed.