Trying to make a flashing Safety Car sign for a racing game, got the sign to turn on and work as I wanted to but I cannot seem to figure out how to get it to turn off.
My script:
function onClicked()
lightOn = true
while lightOn == true do
repeat
workspace.sclight.s.BrickColor = BrickColor.new("Institutional white")
workspace.sclight.s.Material = ("Neon")
workspace.sclight.c.BrickColor = BrickColor.new("Institutional white")
workspace.sclight.c.Material = ("Neon")
workspace.sclight.amber.BrickColor = BrickColor.new("Deep orange")
workspace.sclight.amber.Material = ("Neon")
wait(0.25)
workspace.sclight.amber.BrickColor = BrickColor.new("Reddish brown")
workspace.sclight.amber.Material = ("Plastic")
wait(0.25)
until lightOn == false
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
sclight.s being the “S”
sclight.c being the “C”
sclight.amber being the flashing square around the text
Why not adding your loop code inside another script, parenting this script to the sign and clicking the button would just disabled or enabled the script inside the button?
script.Parent.ClickDetector.MouseClick:connect(function()
if YourSignScript.Disabled == false then
YourSignScript.Disabled = true
else
YourSignScript.Disabled = false
end
end)
Okay, put the code in. Whenever I test in studio, the lights are already on and flashing, however when the button is pressed it essentially pauses the script, should I add something like this to the script?
while false do
sclight.BrickColor = BrickColor.new("Dark stone grey")
sclight.Material = ("Plastic")
cclight.BrickColor = BrickColor.new("Dark stone grey")
cclight.Material = ("Plastic")
aclight.BrickColor = BrickColor.new("Reddish Brown")
aclight.Material = ("Plastic")
end
it isn’t necessary because the script button i gave you before litteraly disabled the script or enabled it. When you enable a disabled script, it does restart him. You want to fully shut down the light when disabled? just set the material and brickcolor when you disable the script, on the button script
Hmm, you know you can simply invert a variable right? 5 lines of code…
function onClicked()
lightOn = not lightOn -- This is how you invert a boolean
while lightOn do
workspace.sclight.s.BrickColor = BrickColor.new("Institutional white")
workspace.sclight.s.Material = ("Neon")
workspace.sclight.c.BrickColor = BrickColor.new("Institutional white")
workspace.sclight.c.Material = ("Neon")
workspace.sclight.amber.BrickColor = BrickColor.new("Deep orange")
workspace.sclight.amber.Material = ("Neon")
wait(0.25)
workspace.sclight.amber.BrickColor = BrickColor.new("Reddish brown")
workspace.sclight.amber.Material = ("Plastic")
wait(0.25)
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
I there may be a better way to write this code but I think that solution you gave already should do the trick.