Debounce not working

I was working on a debounce system but it didn’t work properly. Where’s the problem at? Any help is appreciated! Thanks.

Local script:

local uis = game:GetService("UserInputService")
local cd = 10
local db = false

uis.InputBegan:Connect(function(input, gpe)
	if not gpe then
		if input.KeyCode == Enum.KeyCode.E then
			if db == false then
				local db = true
				game.ReplicatedStorage:WaitForChild("LocalServer"):FireServer()
				wait(cd)
				db = false
			end
		end
	end
end)

replace your script with this and check

local uis = game:GetService("UserInputService")
local cd = 10
local db = false

uis.InputBegan:Connect(function(input, gpe)
	if not gpe and input.KeyCode == Enum.KeyCode.E and not db then
		db = true
		game.ReplicatedStorage:WaitForChild("LocalServer"):FireServer()
		wait(cd)
		db = false
	end
end)
1 Like

It worked! Thanks! Can you tell me where’s the problem at?

after all the if statements you used local db = true which should be db = true because you are not creating new variable “db” and just using the existing variable “db”

1 Like

alright thanks! Sorry for the careless mistake :sweat_smile:

1 Like