Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is this the right script for a traffic light?

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

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

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) 



2 comments

0

I forgot to mention, you want 3 ends at the end of this script.

0

Scratch that, delete the last two "while true do" and make there only 1 end. Sorry.

This discussion is preserved as it was. New answers, comments, and votes are closed.