Debounce Module doesn't work

I made a module script using os.clock but it always return true and it doesn’t work.

Module Script:

--// Services
local Players = game:GetService("Players")

local Debounce = {}

local DebounceHandler = {}

DebounceHandler.Debounce = function(Player, DebounceName, Cooldown)
	if Debounce[Player.UserId][DebounceName] == nil or 0 then
		Debounce[Player.UserId][DebounceName] = os.clock()
		
		return true
		
	else
		if os.clock - Debounce[Player.UserId][DebounceName] >= Cooldown then
			Debounce[Player.UserId][DebounceName] = os.clock()
			
			return true
		else
			return false
		end
	end
end

function DebounceHandler:Int()
	
	Players.PlayerAdded:Connect(function(Player)
		Debounce[Player.UserId] = {
			["BlowDebounce"] = 0,
			["SellDebounce"] = 0,
		}
		
		print(Debounce)
	end)
	
	Players.PlayerAdded:Connect(function(Player)
		Debounce[Player.UserId] = nil
	end)
end

return DebounceHandler

Script:

if DebounceHandler.Debounce(Player, "BlowDebounce", 0.5) == true then
   print(true)
else
   print(false)
end

I’m not sure if this is the issue but on the line

if os.clock - Debounce[Player.UserId][DebounceName] >= Cooldown then

you don’t call os.clock

It still doesn’t work Idk why.

I see a few errors with your module, in your init function you are connecting to the player added event twice, resulting in the player being removed from the module. Next, I would add a loop for any existing players incase a player joins before the script is called. You can do this with a script like this

function DebounceHandler:Int()
	
    for _, player in (Players:GetPlayers()) do
		Debounce[Player.UserId] = {
			["BlowDebounce"] = 0,
			["SellDebounce"] = 0,
		}
    end

	Players.PlayerAdded:Connect(function(Player)
		Debounce[Player.UserId] = {
			["BlowDebounce"] = 0,
			["SellDebounce"] = 0,
		}
		
		print(Debounce)
	end)
	
	Players.PlayerRemoving:Connect(function(Player)
		Debounce[Player.UserId] = nil
	end)
end

This will loop through any existing players so they are added to the debounce table.

Give this a try and let me know if it works.

When you defined the debounces:

Debounce[Player.UserId] = {
		["BlowDebounce"] = 0,
		["SellDebounce"] = 0,
}

You set them all to zero, so when you check for whether or not the player has waited a long enough time, the number will be negative and be unable to be greater than or equal to the cooldown. The default numbers should be the current time:

local CurrentTime = os.clock()
Debounce[Player.UserId] = {
		["BlowDebounce"] = CurrentTime,
		["SellDebounce"] = CurrentTime,
}
if Debounce[Player.UserId][DebounceName] == nil or 0 then

this appears to be true as well, unless other code modifies Debounce
also or 0 will always be false

The script still doesn’t work.

I think the question is what does “working” mean, I don’t see any errors but it looks like the code doesn’t do what you want, could you explain your updated code and what the goal and process is?