No, I’m not trying to “break” the loop. I’m trying to temporarily pause it then resume it later.
I’m attempting to make an ELS (Emergency Lighting System) system, however when I want the lights to turn off I want to make the lights turn off immediately. However, before it does, the full lighting script plays out before it turns off. This is a big problem with lights that have longer wait times.
Script: (script of only one of the lighting groups)
No, I want a way for the scripts inside to immediately come to a halt once a value is turned on, similarly like the “break” line, but I want it to only be temporarily stopped.
Once the “value” is turned on, whatever in the script you provided will only stop after 1 second. I want that to be immediate.
With this script, the only thing changed is detecting if the values were on, now the goal is that if there was a light pattern that lasted 1 second before changing, and the lights were to be turned off before the 1 second gone by, that light would be turned off immediately without needing to wait for that line of script to run.
You could use the GetPropertyChangedSignal for the boolvalue and a variable controls the status of the loop. The reason for the loop ID is to catch any cases where multiple while loops were created due to all of the waits in the while loop.
I haven’t tested the code but I hope that this would work in your situation.
Edit 3: I just realized how bad the last code was but we can make use of threads and cancel them so that the loop will immediately terminate and will ignore any yields since your ELS system had a lot of waits
local ELS = BoolValue
local thread = nil
ELS:GetPropertyChangedSignal("Value"):Connect(function()
if ELS.Value == true then
thread = task.spawn(function()
while true do
task.wait(0.25)
print("ELS ACTIVE")
-- lighting system code
end
end)
elseif ELS.Value == false then
print("deactivated")
task.cancel(thread)
-- turn off lights
end
end)