script.Parent.Enabled = true wait(2) script.Parent.Enabled = false wait(.25) script.Parent.Enabled = true wait(.25) script.Parent.Enabled = false wait(.25) script.Parent.Enabled = true wait(.2) script.Parent.Enabled = false
I'm trying to make this script make a light (it's parent) flicker on and off, how would I make it loop? Thanks!
To repeat an area of code you use a loop. In this case, a while
loop should be used.
while
loops take the form of,
while condition do --code end
If the condition is met, it will repeat itself until the condition is not met.
If the condition is met, we say that the condition is true. If it is not met, we say that the condition is false. In while
loops, the condition must be true in order to continue with the loop.
So how do we make something loop continuously? Well, all we must do is give the while
loop a condition that will never be false. This could really be any number of things, but a fool proof way to give a loop a condition that will always be true is to give it true
itself!
while true do --code end
Obviously, if we give the loop true
as the condition, it will never equal false. Now we have an eternal loop.
CAUTION: Eternal loops must have at least a wait()
somewhere inside them or they will crash the game.
Take a look at these questions concerning while loops;
Do the following while what is true?
They have some very good explanations.