Function aint workin right

funtion suppose to do what its name says, create a cooldown and check if that cooldown exist and if its over or not, I think the “CreateCooldown” function isn’t working properly or the way im checking the cooldown using the “CanUse” function is wrong. Any ideas?

local cooldowns = {}
local function CreateCooldown(inputCooldown, cooldown)
	cooldowns[inputCooldown] = os.clock()
	print("created a cool down for ", inputCooldown)
end
local function CanUse(inputCooldown, cooldown)
	print("canUse function fired")
	if table.find(cooldowns, inputCooldown) then
		print("found ", inputCooldown, " cooldown with a cooldown of ", cooldown)
		local last = cooldowns[inputCooldown]
		if os.clock() - last >= cooldown then
			print(inputCooldown, " cooldown ended")
			return true
		else
			print(inputCooldown, " cooldown did not end")
			return false
		end	
	else
		return true
	end
end
if input == "input" and CanUse("input", 10) == true then			
	print("parry not in cooldown")
	local parryValue = Values:FindFirstChild("Parry")
	if parryValue.Value == false then
		CreateCooldown("input", 2)
	end
else
	print("parry in cooldown")
end

1 Like

If you want you can add prints in your code to show where it stops working.

Also what’s not working with it?

And, you don’t need to use else for return false, as if it returns true it will stop the function.

You are indexing it as a dictionary, which is why

this doesn’t work. table.find() is used for finding values in arrays, and not dictionaries. Try using cooldowns[inputCooldown] instead.

1 Like

You should change

if table.find(cooldowns, inputCooldown) then

To

if cooldowns[inputCooldown] then
1 Like