Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the following script loop continuously?

Asked by 10 years ago
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!

0
I've tried 'Repeat until' but I don't know what to put after the until... nightmare13542 45 — 10y
0
I edited my post with some more questions about while true do! Take a look at them! Perci1 4988 — 10y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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?

What is while true do?

What does while true do mean?

They have some very good explanations.

0
Awesome! Thanks! nightmare13542 45 — 10y
Ad

Answer this question