So I have a siren script, and I want it when you press "F", a loop plays of the siren turning off and on, and then when you press "F" again, then it turns off. It works, but I added a loop, i,v in pairs do, but when I added it the script stopped working completely? How would I add a loop, plus the debounce and else? Here is the script:
local event = script.Parent.Parent.SirenEventOn
local leftsiren = script.Parent.Parent.Parent.Parent.Parent.Body.Sirens.LeftLight
local rightsiren = script.Parent.Parent.Parent.Parent.Parent.Body.Sirens.RightLight
local leftlight = script.Parent.Parent.Parent.Parent.Parent.Body.Sirens.LeftLight.Light
local rightlight = script.Parent.Parent.Parent.Parent.Parent.Body.Sirens.RightLight.Light
local db = false
event.OnServerEvent:Connect(function(player)
if not db then
db = true
wait(0.5)
for i,v in pairs do
leftsiren.Transparency = 0
leftlight.Enabled = true
rightsiren.Transparency = 1
rightlight.Enabled = false
wait(0.5)
leftsiren.Transparency = 1
leftlight.Enabled = true
rightsiren.Transparency = 0
rightlight.Enabled = false
else
leftsiren.Transparency = 1
leftlight.Enabled = false
rightsiren.Transparency = 1
rightlight.Enabled = false
break
db = false
end
end
end)

2 comments
The way you're using the "for" loop is for iterating through tables. A while statement is preferred if you just want something to run constantly, a set number of times, or until a condition is met.
ah, I see so like while true then?