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

How do I make these stop the second the button is clicked? (UNSOLVED)

Asked by 10 years ago

This is a lightbar, It works and lights up all of the lights except when I click the screengui button it takes a minute for the script to finish and turn off. Is there a way to make the script stop wherever and be instant off?

On=false 
function onClicked() 
if On then On=false else 
On=true 
while On do 

    game.Workspace.Test1.Light1.BrickColor = BrickColor.new("Really red") 

    game.Workspace.Test1.Light2.BrickColor = BrickColor.new("Medium stone grey")  

    game.Workspace.Test1.Light3.BrickColor = BrickColor.new("Really red")

    game.Workspace.Test1.Light4.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light5.BrickColor = BrickColor.new("Really red")

    game.Workspace.Test1.Light6.BrickColor = BrickColor.new("Medium stone grey")

    wait(0.5) 

    game.Workspace.Test1.Light1.BrickColor = BrickColor.new("Medium stone grey") 

    game.Workspace.Test1.Light2.BrickColor = BrickColor.new("Really red")  

    game.Workspace.Test1.Light3.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light4.BrickColor = BrickColor.new("Really red")

    game.Workspace.Test1.Light5.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light6.BrickColor = BrickColor.new("Really red") 

    wait(0.5)

    game.Workspace.Test1.Light1.BrickColor = BrickColor.new("Really red") 

    game.Workspace.Test1.Light2.BrickColor = BrickColor.new("Medium stone grey")  

    game.Workspace.Test1.Light3.BrickColor = BrickColor.new("Really red")

    game.Workspace.Test1.Light4.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light5.BrickColor = BrickColor.new("Really red")

    game.Workspace.Test1.Light6.BrickColor = BrickColor.new("Medium stone grey")

    wait(0.5) 

    game.Workspace.Test1.Light1.BrickColor = BrickColor.new("Medium stone grey") 

    game.Workspace.Test1.Light2.BrickColor = BrickColor.new("Medium stone grey")  

    game.Workspace.Test1.Light3.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light4.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light5.BrickColor = BrickColor.new("Medium stone grey")

    game.Workspace.Test1.Light6.BrickColor = BrickColor.new("Medium stone grey")

    wait(0.5)
end 
end 
end 

script.Parent.MouseButton1Down:connect(onClicked) 

Answer this question