I’m making a simple script for police lights using a while loop and functions as shown below.
However, when trying to shut off the lights, the script has to run through whats left of the light pattern before shutting off. This will be a problem when I add longer and more advanced light patterns. How would I instantly break the while loop when the value changes?
I tried looking for some solutions online but found none.
local status = script.Parent.Status
status.Changed:Connect(function()
if status.Value == true then
while status.Value == true do
allBlues() -- Turns on all blue lights
wait(.4)
allReds() -- Turns on all red lights
wait(.4)
end
elseif status.Value == false then
while status.Value == false do
allOff() -- Turns off all lights
wait(.5)
end
end
end)