Why is my DB not working?

Hello, i have a db and it works for one actually duration then it’s just spam able
heres the script

db = true
script.Punch.OnServerEvent:Connect(function(plr)
	print("f")
	if db == true then
	db = false
	fist1 = game.Lighting.Folder.Fist1:Clone()
	fist2 =  game.Lighting.Folder.Fist2:Clone()
	fist3 =  game.Lighting.Folder.Fist3:Clone()
	print("f2")
	plr.Character.Humanoid.WalkSpeed = 1 
	wait(1)
	plr.Character["Right Arm"].Transparency = 1
	plr.Character["Left Arm"].Transparency = 1
	fist1.Parent = game.Workspace
	fist2.Parent = game.Workspace
	fist3.Parent = game.Workspace
	plr.Character.Humanoid.WalkSpeed = 1 
	old = fist1.Size
	fist1.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(2,1,-3)
	fist2.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(-2,2,-3)
	fist3.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(-2,0,-3)
	fist1.Anchored = true
	fist2.Anchored = true
	fist3.Anchored = true
	r = 10
	repeat wait(0)
		fist1.Size = fist1.Size + Vector3.new(0,0,1.5)
	fist1.CFrame = fist1.CFrame * CFrame.new(0,0,.01)		
		fist2.Size = fist2.Size + Vector3.new(0,0,1.5)
	fist2.CFrame = fist2.CFrame * CFrame.new(0,0,.01)		
		fist3.Size = fist3.Size + Vector3.new(0,0,1.5)
	fist3.CFrame = fist3.CFrame * CFrame.new(0,0,.01)
		r = r + 1
	until r == 20
	repeat wait(0)
	fist1.Size = fist1.Size - Vector3.new(0,0,1.5)
	--fist1.CFrame = fist1.CFrame * CFrame.new(0,0,0.7)		
	fist2.Size = fist1.Size - Vector3.new(0,0,1.5)
	--fist2.CFrame = fist2.CFrame * CFrame.new(0,0,0.7)		
	fist3.Size = fist1.Size - Vector3.new(0,0,1.5)
	--fist3.CFrame = fist3.CFrame * CFrame.new(0,0,0.7)
	r = r + 1	
	until r == 35
    fist1:Destroy()
	fist2:Destroy()
	fist3:Destroy()
	plr.Character["Right Arm"].Transparency = 0
	plr.Character["Left Arm"].Transparency = 0
	plr.Character.Humanoid.WalkSpeed = 16 
	end
	wait(15)

	db = true
end)

You need to set db = true inside of the if statement.
The reason being is because if db is false, it will just wait 15 seconds and then set it to true, which is why it’s spamable after the first shot. Hope this helps!

1 Like

Just a small thing I’d like to point out: unless you want the debounce to apply for all players at once (meaning that only one player can do whatever action at a time), you should make a seperate debounce for each player:

local Players = game:GetService("Players")
local db = {}

Players.PlayerAdded:Connect(function(plr)
    db[plr] = true
end)
Players.PlayerRemoving:Connect(function(plr)
    db[plr] = nil
end)

-- To access the player's debounce in the OnServerEvent function
if db[plr] == true then
-- ...
2 Likes

Thanks, you saved me a lot of time in the future!

This is a little off topic, but try use server storage(only server can see items) or replicated storage(client and server can see items) instead of lighting.

1 Like