Cooldown for tool activated

how do i make it cooldown 1 sec before sending anoither clone/ activate a tool again

local model = script.dmg
script.Parent.Activated:Connect(function()
	---
	local clone = model:Clone()
	script.Sound:Play()
	clone.Parent = script
wait(.9)
	clone:Destroy()
end)

ive tried using wakt after end) dindt work

2 Likes

wait() is deprecated and replaced by task library.

Also, it’s because every time your event is fired, a new thread is created (think of it as a new script to run whatever that is contained inside the event). This is to prevent any unexpected errors from pausing the entire execution of the script.

To add a cooldown or a debounce, refer to this tutorial.

1 Like
local debounce = false
local model = script.dmg
script.Parent.Activated:Connect(function()
    if debounce then
        return
    end
    debounce = true
	local clone = model:Clone()
	script.Sound:Play()
	clone.Parent = script
    task.wait(.9)
	clone:Destroy()
    debounce = false
end)
1 Like

There are multiple ways to do this, but this is my preferred:

local cooldown = 1
local lastActivate = 0

script.Parent.Activated:Connect(function()
	if os.clock - lastActivate < cooldown then
		return
	end

	lastActivate = os.clock()

	local clone = model:Clone()
	script.Sound:Play()
	clone.Parent = script

	task.wait(.9) --wait() is deprecated, use task.wait() instead.
	clone:Destroy()
end)
1 Like