Debounce not working for some reason?

can someone help with my script not working? it should work but I don’t know why it’s not working

i’ve tried changing where the debounce is but if I do that the debounce doesn’t work

local uis = game:GetService("UserInputService")
local key = Enum.KeyCode.E
local db = false
local ev = script:WaitForChild("mainEvent")
local cdTime = 10 -- seconds
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

uis.InputBegan:Connect(function(input,istyping)
	
	if not db then
		db = true
		
		if input.KeyCode == (key) and not istyping then
			print('key pressed')

			mouse.Button1Down:Connect(function()
				print('clicked')
				ev:FireServer(mouse.Hit.Position)
			end)

		end
		
		wait(cdTime)
		
		db = false
		print('Cooldown Over')
		
	end

end)
1 Like

Try using this:

if db then
     return
end
db = true
--Code goes here
db = false

Have your cooldown go before the db = false

tried it and it’s still the same:

local uis = game:GetService("UserInputService")
local key = Enum.KeyCode.E
local db = false
local ev = script:WaitForChild("mainEvent")
local cdTime = 10 -- seconds
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

uis.InputBegan:Connect(function(input,istyping)
	
	if db then
		return
	end
	db = true
	
	if input.KeyCode == (key) and not istyping then
		print('key pressed')

		mouse.Button1Down:Connect(function()
			print('clicked')
			ev:FireServer(mouse.Hit.Position)
		end)

	end
	
	wait(cdTime)
	
	db = false
	print('Cooldown Over')

end)

Try having your debounce inside Button1Down

1 Like

it works now thanks‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎ ‎‎‎ ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎

1 Like