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

Can you fix this script?

Asked by
awfulszn 394 Moderation Voter
9 years ago

What I want is when the script runs and everything finishes, I want it to repeat itself forever and keep starting from beginning one finished.

01local BPD = game.Workspace.BasePlate -- Changes the name of BasePlate in the script.
02 
03wait(5)
04if BPD.BrickColor == BrickColor.White() then -- If the BasePlate (BPD) is White then,
05wait(2)
06    BPD.BrickColor = BrickColor.Yellow()
07    wait(2)
08    BPD.BrickColor = BrickColor.Black()
09    wait(2)
10    BPD.BrickColor = BrickColor.Red()
11    wait(2)
12    BPD.BrickColor = BrickColor.Blue()
13    wait(2)
14    BPD.BrickColor = BrickColor.Gray()
15    wait(2)
View all 21 lines...

4 answers

Log in to vote
0
Answered by
wackem 50
9 years ago
01local BPD = game.Workspace.BasePlate -- Changes the name of BasePlate in the script.
02 
03wait(5)
04if BPD.BrickColor == BrickColor.new("White") then -- If the BasePlate (BPD) is White then,
05while true do
06wait(2)
07    BPD.BrickColor = BrickColor.new("Yellow")
08    wait(2)
09    BPD.BrickColor = BrickColor.new("Black")
10    wait(2)
11    BPD.BrickColor = BrickColor.new("Red")
12    wait(2)
13    BPD.BrickColor = BrickColor.new("Blue")
14    wait(2)
15    BPD.BrickColor = BrickColor.new("Gray")
View all 22 lines...

should work.

Ad
Log in to vote
1
Answered by
woodengop 1134 Moderation Voter
9 years ago

Loop

There are many loops in lua such as : For,While, and Repeat loops, In this case, you want to loop forever, use the While loop, this loop continues looping until the condition is nil or false.

01local Part=workspace.Baseplate -- define ( Part=Location)
02local Colors={BrickColor.Yellow(),BrickColor.Black(), BrickColor.Red(),BrickColor.Blue()}-- Place all your colors in the array
03wait(5)
04if Part.BrickColor==BrickColor.White() then
05    while wait(2) do -- do add a wait() function to prevent crashes
06        for i=1,#Colors do
07            Part.BrickColor=Colors[i]
08        end
09    end
10end
0
Use while wait() do, it's the same has while true and wait() do but shorter EzraNehemiah_TF2 3552 — 9y
0
Or even better, while wait(2) do; That way you can remove the wait(2) from the other segment DigitalVeer 1473 — 9y
Log in to vote
0
Answered by 9 years ago

Use DangCoolIsReal's idea but I'll make it shorter

1local BPD = game.Workspace.BasePlate
2Colors = {BrickColor.Yellow,BrickColor.Black,BrickColor.Red,BrickColor.Blue,BrickColor.Gray,BrickColor.DarkGray,BrickColor.Green,BrickColor.White,}
3while wait() do
4    for i = 1, 8 do
5        BPD.BrickColor = Colors[i]()
6        wait(2)
7    end
8end
Log in to vote
-1
Answered by 9 years ago
01local BPD = game.Workspace.BasePlate
02 
03local Colors = {
04    [1] = BrickColor.Yellow,
05    [2] = BrickColor.Black,
06    [3] = BrickColor.Red,
07    [4] = BrickColor.Blue,
08    [5] = BrickColor.Gray,
09    [6] = BrickColor.DarkGray,
10    [7] = BrickColor.Green,
11    [8] = BrickColor.White,
12}
13 
14wait(5)
15 
View all 23 lines...

Why so many downvotes?

0
I have to downvote because your 23 lined script can actually be 8 lined EzraNehemiah_TF2 3552 — 9y

Answer this question