Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me put a debounce/cooldown on my/this script ???

tool = script.Parent

handle = tool:WaitForChild("Handle")

local Debounce = false

tool.Equipped:Connect(function()

print("The Tool Was Equipped")

tool.Handle.ParticleEmitter.LockedToPart = true

tool.Sound:Play()

end)

tool.Activated:Connect(function()

print("nice")

script.Parent.Parent.Humanoid:LoadAnimation(script.Animation):Play()

tool.Handle.ParticleEmitter.LockedToPart = false

tool.Handle.ParticleEmitter.EmissionDirection = ("Front")

tool.Handle.ParticleEmitter.Lifetime = NumberRange.new(3,3)

tool.Handle.ParticleEmitter.Acceleration = Vector3.new(0, 0.5, 0)

wait(2.5)

tool.Handle.ParticleEmitter.Lifetime = NumberRange.new(0.5,0.5)

tool.Handle.ParticleEmitter.Acceleration = Vector3.new(0, 0, 0)

script.Parent.Parent.Humanoid:LoadAnimation(script.Animation):Stop()

wait(2.5)

tool.Handle.ParticleEmitter.EmissionDirection = ("Top")

tool.Handle.ParticleEmitter.LockedToPart = true

end)


tool.Unequipped:Connect(function()

print("The Tool Was Unequipped")

tool.Sound:Stop()

script.Parent.Parent.Humanoid:LoadAnimation(script.Animation):Stop()

end)

tool.Deactivated:Connect(function()

print("The Tool Has Been Deactivated")

end)


please help me put a cooldown or debounce whatever on this script like When it's activated I need to wait another 6 seconds to be able to activate it again "This script is on a tool on starterpack, I use Left click to Activate"

2 answers

local debounce = true
if not debounce then return end
-- code

Just set the debounce to false when you want them to no longer be able to use it, then add a wait(6) and set it back to true when they are able to use it again.

no do this instead:

local debounce = false
tool.Activated:Connect(function()
if not debounce then--runs the function
debounce = true--stops the function from running again
the function in here
wait(3)--for 3 seconds
debounce = false-- the function can run again

This discussion is preserved as it was. New answers, comments, and votes are closed.