Help with a BoolValue loop

I am trying to do a script where if the boolvalue is true then it would loop the flashing lights on and off constantly but when the boolvalue goes false it turns the lights off completely. Can anyone help me with this regard?

All help is greatly appreciated.
Jamie

1 Like

Scripting Support is meant to help people with existing scripts, not create new ones based on what you describe.

My apologies, quite new to the forum so getting used to the system still.

local function LoopBool()
   while BoolValue.Value do
      -- Do whatever here
   end
end

BoolValue.Changed:Connect(function()
   if BoolValue.Value then
      LoopBool()
end)


It turn’s the lights on but won’t turn them back off again…

I’m not an expert at coding either, but try this and put it at the bottom of the while loop:

if game.ReplicatedStorage.AlarmTriggered.Value = false then
break
end

(Although it’s not going to turn off because it has to meet a condition in order to turn it off whether you want it to wait 30 seconds, etc)

Sadly this did not work either, was worth a try. I tried it with the:

if game.ReplicatedStorage.AlarmTriggered.Value == false then
break
end

However that did not work.

It didn’t turn off because you haven’t stated how and when you want it to turn off completely.

If possible could you explain a bit more?
So if I put the script:

if game.ReplicatedStorage.AlarmTriggered.Value == false then
break
end

What else would I need to add to it?

Essentially when the Boolean value is false it breaks out of the loop, although the condition for the AlarmTriggered has to be false in order to do that. Though you haven’t told us when you want that condition to be met.

Thank you for explaining this more, I have now fixed it and it works fine!
Your help and everyone else’s help was appreciated! :grin:

1 Like