Command fires bindableevent twice instead of once

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

script.Parent.Event:connect(function()

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

How do you know it fires twice? Does it print started alarm twice in a row? If so, perhaps you accidently duplicated the script?

Also can you show the code which fires the BindableEvent?


btw next time please format your code by putting it around 3 tickmarks, like this:

```
code here
```
here's op's formatted code in case anyone else is too lazy to format/indent it
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

script.Parent.Event:connect(function()
	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
1 Like

it prints “started alarm” and “stopped alarm” at the same time, also no i haven’t duplicated the script.

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
1 Like

Thank you now with debounce it works.