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

Is this the right script for a traffic light?

Asked by 10 years ago

For red....

while true do
game.Workspace.RedLight.BrickColor = ("Bright red")
wait(30)
game.Workspace.RedLight.BrickColor = ("Really red")
wait(30)
end

For green

while true do
game.Workspace.GreenLight.BrickColor = ("Camo")
wait(60)
game.Workspace.GreenLight.BrickColor = ("Lime green")
wait(60)
end

For Yellow

while true do
game.Workspace.YellowLight.BrickColor = ("Bright yellow")
wait(120)
game.Workspace.YellowLight.BrickColor = ("New Yeller")
wait(120)
end

Help?

2 answers

Log in to vote
2
Answered by
Sublimus 992 Moderation Voter
10 years ago

Since it is three separate loops, you will have it overlap sometimes, try this:

red = game.Workspace.RedLight
yellow = game.Workspace.YellowLight
green = game.Workspace.GreenLight
while true do
    green.BrickColor = BrickColor.new("Lime green")
    wait(30) -- Time you want light to be green
    green.BrickColor = BrickColor.new("Camo")
    yellow.BrickColor = BrickColor.new("Bright yellow")
    wait(15) -- Time you want light to be yellow
    yellow.BrickColor = BrickColor.new("New Yeller")
    red.BrickColor = BrickColor.new("Really red")
    wait(30) -- Time you want light to be red
    red.BrickColor = BrickColor.new("Bright red")
end
Ad
Log in to vote
-2
Answered by 10 years ago

Well you will have a problem because the way you have it set up. It will make each light run on their own time. So try something like this,


while true do game.Workspace.RedLight.BrickColor = ("Bright red") wait(30) game.Workspace.RedLight.BrickColor = ("Really red") wait(30) while true do game.Workspace.GreenLight.BrickColor = ("Camo") wait(30) game.Workspace.GreenLight.BrickColor = ("Lime green") wait(30) while true do game.Workspace.YellowLight.BrickColor = ("Bright yellow") wait(10) game.Workspace.YellowLight.BrickColor = ("New Yeller") wait(30)
0
I forgot to mention, you want 3 ends at the end of this script. GianniKun 40 — 10y
0
Scratch that, delete the last two "while true do" and make there only 1 end. Sorry. GianniKun 40 — 10y

Answer this question