How do I make this repeat?
game.workspace.Base.Transparency=0.1 wait(0.5) game.workspace.Base.Transparency=0.2 wait(0.5) game.workspace.Base.Transparency=0.3 wait(0.5) game.workspace.Base.Transparency=0.4 wait(0.5) game.workspace.Base.Transparency=0.5 wait(0.5) game.workspace.Base.Transparency=0.6 wait(0.5) game.workspace.Base.Transparency=0.7 wait(0.5) game.workspace.Base.Transparency=0.8 wait(0.5) game.workspace.Base.Transparency=0.9 wait(0.5) game.workspace.Base.Transparency=1 wait(0.5) game.workspace.Base.CanCollide=false wait(0.5) game.workspace.Base.CanCollide=true game.workspace.Base.Transparency=0.9 wait(0.5) game.workspace.Base.Transparency=0.8 wait(0.5) game.workspace.Base.Transparency=0.7 wait(0.5) game.workspace.Base.Transparency=0.6 wait(0.5) game.workspace.Base.Transparency=0.5 wait(0.5) game.workspace.Base.Transparency=0.4 wait(0.5) game.workspace.Base.Transparency=0.3 wait(0.5) game.workspace.Base.Transparency=0.2 wait(0.5) game.workspace.Base.Transparency=0.1 wait(0.5) game.workspace.Base.Transparency=0 wait(0.5)
HOLD UP! Before we get into repeating your code, it's probably safe to assume that your code is WAY to long for what it could actually be.
To give a quick example of how we can change your code, let's first do something else.
Let's make a script that prints every number from 1 to 10:
print(1) print(2) print(3) print(4) print(5) print(6) print(7) print(8) print(9) print(10)
Now, the above code does indeed get the job done.
However, we can make the code a LOT shorter.
Take a look at this:
for i = 1, 10 do print(i) end
What was done above is called a loop
. It allows you to go through a series of value(s) very easily. Basically, it sets the variable 'i' to 1. Each time the chunk of code between the 'for' and the 'end' has finished running, 'i' will increase by '1'. It does this till it reaches 11. That's why the code will print every number from 1 - 10 inclusive.
We can even change the increment by adding a third number!
for i = 1, 10,2 do print(i) end
The third number will print the code at counts of '2'.
So it will print, 1, 3, 5, 7, 9, 10
Now, let's make your code shorter AND repeat.
for transparency = .1,1,.1 do workspace.Base.Transparency = transparency wait(.5) end workspace.Base.CanCollide = false wait(.5) workspace.Base.CanCollide = true for transparency = 1,.1,-.1 do workspace.Base.Transparency = transparency wait(.5) end
Great! We've shortened your code by using a loop, but let's make it repeat forever. We can use a while loop to achieve this.
while true do for transparency = .1,1,.1 do workspace.Base.Transparency = transparency wait(.5) end workspace.Base.CanCollide = false wait(.5) workspace.Base.CanCollide = true for transparency = 1,.1,-.1 do workspace.Base.Transparency = transparency wait(.5) end end
Basically, a while loop will keep repeating if whatever you put between the 'while' and 'do' is true. So if we put 'true', then it will repeat forever since true is always true. [Sorry if that sounds weird]
There are a lot of sources that teach loops. Loops are a highly essential part to certain aspects of coding.
http://wiki.roblox.com/index.php?title=Basic_Scripting
http://wiki.roblox.com/index.php?title=Loops
http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
You code is extremely inefficient, I suggest a for loop and a while loop..
Brick = game.Workspace.Base for i = (0, 1, 0.1) -- This is saying go from 0 to 1 in steps of 0.1, so this will loop 10 times, and "i" will get gradually bigger, increasing the transparency on the next line. Brick.Transparency = i wait(0.5) end
These 4 lines of code will make your Brick's transparency go from 0 to 1, gradually over the course of 5 seconds, in these 4 lines we have done your lines 2 - 21.
The next 3 Lines are fine:
Brick.CanCollide = false wait(0.5) Brick.CanCollide = true
Then the transparency back down again:
for i = (1, 0, -0.1) Brick.Transparency = i wait(0.5) end
Now to make this loop forever, put it in a while loop, these loops loop foreveruntil told to break.
Example:
while true do print ("Hello World!") end
This will print Hello World! forever!
So your full code is:
Brick = game.Workspace.Base while true do for i = (0, 1, 0.1) -- This is saying go from 0 to 1 in steps of 0.1, so this will loop 10 times, and "i" will get gradually bigger, increasing the transparency on the next line. Brick.Transparency = i wait(0.5) end Brick.CanCollide = false wait(0.5) Brick.CanCollide = true for i = (1, 0, -0.1) Brick.Transparency = i wait(0.5) end end
With these efficient loops we have made your 43 lines of code into 17
This is easy, just do
repeat game.workspace.Base.Transparency=0.1 wait(0.5) game.workspace.Base.Transparency=0.2 wait(0.5) game.workspace.Base.Transparency=0.3 wait(0.5) game.workspace.Base.Transparency=0.4 wait(0.5) game.workspace.Base.Transparency=0.5 wait(0.5) game.workspace.Base.Transparency=0.6 wait(0.5) game.workspace.Base.Transparency=0.7 wait(0.5) game.workspace.Base.Transparency=0.8 wait(0.5) game.workspace.Base.Transparency=0.9 wait(0.5) game.workspace.Base.Transparency=1 wait(0.5) game.workspace.Base.CanCollide=false wait(0.5) game.workspace.Base.CanCollide=true game.workspace.Base.Transparency=0.9 wait(0.5) game.workspace.Base.Transparency=0.8 wait(0.5) game.workspace.Base.Transparency=0.7 wait(0.5) game.workspace.Base.Transparency=0.6 wait(0.5) game.workspace.Base.Transparency=0.5 wait(0.5) game.workspace.Base.Transparency=0.4 wait(0.5) game.workspace.Base.Transparency=0.3 wait(0.5) game.workspace.Base.Transparency=0.2 wait(0.5) game.workspace.Base.Transparency=0.1 wait(0.5) game.workspace.Base.Transparency=0 wait(0.5) until 9 + 10 == 21