Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
5 years ago
Edited 5 years ago
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.

Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

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

Answer this question