How i can break the while true do with another button

Alright i made a belisha beacon and i’m scripting the control box, but the thing is i can’'t break the while true do with another button, somewone wants to help me?
here is the off button script:

local part = script.Parent
local click = script.Parent.ClickDetector
local Clicked = false
local lightPart = workspace.YellowUKZebracrossingllight.Light
local lightPart2 = workspace.F.Light
local lightPart3 = workspace.E.Light
local pointLight = lightPart.PointLight
local pointLight2 = lightPart2.PointLight
local pointLight3 = lightPart3.PointLight
local click2 = workspace.Belishabeaconcontrolbox.Normal.ClickDetector

local function On()
if not Clicked then
workspace.Belishabeaconcontrolbox.Off.Sound3:Play()
workspace.Belishabeaconcontrolbox.Normal.Material = Enum.Material.Plastic
workspace.Belishabeaconcontrolbox.Controlbox.Sound:Stop()
workspace.Belishabeaconcontrolbox.Normal.Color = Color3.new(0.45098, 1, 0)
workspace.Belishabeaconcontrolbox.Off.Material = Enum.Material.Neon
click2.MaxActivationDistance = 5
print(“Belisha beacons are off!”)
while true do
break
end
pointLight.Enabled = false
pointLight2.Enabled = false
pointLight3.Enabled = false
end
end
click.MouseClick:Connect(On)

here is the on button script:

local part = script.Parent
local click = script.Parent.ClickDetector
local click2 = workspace.Belishabeaconcontrolbox.Off.ClickDetector
local click3 = workspace.Belishabeaconcontrolbox.Lightson.ClickDetector
local click4 = workspace.Belishabeaconcontrolbox.Lightsoff.ClickDetector
local Clicked = false
local ClickedAgain = false
local lightPart = workspace.YellowUKZebracrossingllight.Light
local lightPart2 = workspace.F.Light
local lightPart3 = workspace.E.Light
local pointLight = lightPart.PointLight
local pointLight2 = lightPart2.PointLight
local pointLight3 = lightPart3.PointLight

local function On()
if not Clicked then
workspace.Belishabeaconcontrolbox.Lightson.Material = Enum.Material.Plastic
workspace.Belishabeaconcontrolbox.Lightsoff.Material = Enum.Material.Plastic
workspace.Belishabeaconcontrolbox.Normal.Material = Enum.Material.Neon
workspace.Belishabeaconcontrolbox.Normal.Color = Color3.new(1, 0.882353, 0.223529)
workspace.Belishabeaconcontrolbox.Normal.Sound:Play()
click4.MaxActivationDistance = 0
click3.MaxActivationDistance = 0
click2.MaxActivationDistance = 0
click.MaxActivationDistance = 0
print(“Belisha beacons are turning on!”)
task.wait(5)
workspace.Belishabeaconcontrolbox.Controlbox.Sound:Play()
task.wait(1)
task.wait(1)
workspace.Belishabeaconcontrolbox.Normal.Color = Color3.new(0.184314, 1, 0)
print(“Belisha beacons are on!”)
click2.MaxActivationDistance = 5
while true do
pointLight.Enabled = true
pointLight2.Enabled = true
pointLight3.Enabled = true
task.wait(0.7)
pointLight.Enabled = false
pointLight2.Enabled = false
pointLight3.Enabled = false
task.wait(0.7)
end
end
end
click.MouseClick:Connect(On)

2 Likes

From what I’m gathering… you want the while loop to end when you click a button? If so this is really easy to implement
Here’s a quick lil excerpt I made
Rather than doing true/using break, just make a boolean variable

local canLoop = true
while (canLoop) do
    --Do your code
end

YOUR_BUTTON.MouseButton1Click:Connect(function()
       canLoop = false
end)