I made script of when you press GUI button it starts police siren. It works fine and well but the only problem you can't stop it. How do I make so that when you click button again, it stops the sirens and the lights too.
Here's my script:
local light = game.Workspace.Lights function onClicked() light.Sound:Play() while true do light.Red.Material = "Neon" light.Blue.Material = "Plastic" light.Red.PointLight.Enabled = true light.Blue.PointLight.Enabled = false wait(0.8) light.Blue.Material = "Neon" light.Red.Material = "Plastic" light.Red.PointLight.Enabled = false light.Blue.PointLight.Enabled = true wait(0.8) end end script.Parent.TextButton.MouseButton1Down:connect(onClicked)
Firstly, if you have filtering enabled on reply to this saying you are as this will not work. In the model put a BoolValue. This will be your yes and no value. Once you have placed that in, use this script.
local light = game.Workspace.Lights function onClicked() -- Your on and off script. if script.Parent.BoolValue.Value == false then script.Parent.BoolValue.Value = true elseif script.Parent.BoolValue.Value == true then script.Parent.BoolValue.Value = false end end script.Parent.BoolValue.Changed:connect(function() if script.Parent.BoolValue.Value == true then light.Sound:Play() while script.Parent.BoolValue.Value == true do light.Red.Material = "Neon" light.Blue.Material = "Plastic" light.Red.PointLight.Enabled = true light.Blue.PointLight.Enabled = false wait(0.8) light.Blue.Material = "Neon" light.Red.Material = "Plastic" light.Red.PointLight.Enabled = false light.Blue.PointLight.Enabled = true wait(0.8) until script.Parent.BoolValue.Value == false light.Sound:Stop() end end end) script.Parent.TextButton.MouseButton1Down:connect(onClicked)
That theoretically should work.