Why does this script not work?

I writing a Cooldown script to prevent player spamming it, but player can still spam it idk why i return the script to dont let player use the move

function MainFunctions.Cooldown(char, SkillName, Duration)
	if not char.PrimaryPart:FindFirstChild(SkillName) then
		
		if char:FindFirstChild("GetDamaged").Value == true then
			repeat
				wait()
			until char:FindFirstChild("GetDamaged").Value == false
		end
		
		local CDValue = Instance.new("BoolValue", char.PrimaryPart)
		CDValue.Name = SkillName
		deb:AddItem(CDValue, Duration)
		local player = game.Players:GetPlayerFromCharacter(char)
		if player then
			local CooldownGUI = ClientItemFolder.GUI.CooldownUI:Clone()
			CooldownGUI.Parent = player.PlayerGui.CooldownGUI.BackGround
			CooldownGUI.Name = SkillName

			CooldownGUI.SkillName.Text = SkillName

			local tweenInfo = TweenInfo.new(Duration, Enum.EasingStyle.Linear)

			local tween = game.TweenService:Create(CooldownGUI.CDBackground.CDBar, tweenInfo, {	
				Size = UDim2.new(0, 0, 1, 0) 		
			})

			tween:Play()

			tween.Completed:Connect(function()
				CooldownGUI:Destroy()
			end)

		end
	else
		return -- this return btw
	end
end

this is how i use it btw
image

Maybe you forgot to put a debounce system, you just put the cooldown but not the debounce thing. Debounce thing is something like this:

local debounce = false
local function functionName (cooldown, moreParameters)
	if not debounce then
		--execute your code
		print("code executing")
		debounce = true
		task.wait(cooldown) --or you can just use wait(), but i prefer task.wait()
		debounce = false
	end
end
--[[debounce will need to be false so the code can execute. when it
executes, it makes the debounce as true, so the code can't be executed
while debouce is true, then it waits the cooldown to put debounce as false
again.]]
1 Like

if not deboucne then

change to

if not debounce then