it worked before, i accidentally removed my last script and i found the same script in drafts. Before the deletion it worked fine (Fired once each command), Now it fires twice (Fires twice each command). There are no errors what do i do please help.
local combines = game.ServerStorage:WaitForChild(“combine_ambush”)
function alarmon()
workspace.AlarmSound.Volume = 4
game.Lighting.lockdowncolor.Enabled = true
combines.Parent = workspace
end
function alarmoff()
combines.Parent = game.ServerStorage
workspace.AlarmSound.Volume = 2
wait(0.1)
workspace.AlarmSound.Volume = 0
game.Lighting.lockdowncolor.Enabled = false
wait(1)
combines.Parent = game.ServerStorage
end
local isalarmon = script.Value.Value
local admins = {"vovcher","Player1"}
local remote = workspace.BlastDoorOpen.Move
local eventfolder = workspace:WaitForChild("EventFolder")
game.Players.PlayerAdded:connect(function(nP)
for _,v in pairs (admins)do
if nP.Name == v then
nP.Chatted:connect(function(msg)
if (msg:lower() == "gatea") then
remote:Fire()
wait(1)
elseif (msg:lower() == "completelockdown") then
eventfolder.alarm_event_holder.Event:Fire()
elseif (msg:lower() == "nuke") then
eventfolder.nuke_event_holder.Event:Fire()
elseif (msg:lower() == "spawnsquad") then
local squad = game.ServerStorage.CombineSquad:Clone()
squad.Parent = workspace
elseif (msg:lower() == "test") then
local combinesa = game.ServerStorage.combine_ambush:Clone()
combinesa.Parent = workspace
end
end)
end
end
end)
At the first glance there isn’t anyhing in your code which would make it fire twice in a row, so I’m not sure what the issue is.
As a bandaid solution, you can add a debounce of i.e. 1 second to the event, so that it cannot be fired within 1 second from each fire:
local combines = game.ServerStorage:WaitForChild("combine_ambush")
function alarmon()
workspace.AlarmSound.Volume = 4
game.Lighting.lockdowncolor.Enabled = true
combines.Parent = workspace
end
function alarmoff()
combines.Parent = game.ServerStorage
workspace.AlarmSound.Volume = 2
wait(0.1)
workspace.AlarmSound.Volume = 0
game.Lighting.lockdowncolor.Enabled = false
wait(1)
combines.Parent = game.ServerStorage
end
local isalarmon = script.Value.Value
local lastFire
script.Parent.Event:connect(function()
if lastFire and tick() - lastFire < 1 then --if it isn't nil and the difference between now and that moment is < 1 second
return --exit the function
end
lastFire = tick()
if isalarmon == false then
isalarmon = true
alarmon()
print("started alarm")
wait(5)
elseif isalarmon == true then
isalarmon = false
alarmoff()
print("stopped alarm")
wait(5)
end
end