Hello! I'm having an issue with adding a cool down to a weapon I made. The goal of the script below is to play an animation and a blast sound whenever the weapon is fired. But I'm trying to add a 2 second cool down to this because the weapon itself has a 2 second reload time and I want the animation and blast sound to match the reload time. But I'm having a hard time implementing this cooldown.
Here's the script below:
local Tool = script.Parent
local AnimationR15 = script:WaitForChild("AnimationR15", 1)
local AnimationR6 = script:WaitForChild("AnimationR6", 1)
local cooldown = 2 -- how long the cooldown will take
local GunSound = game.Workspace.GunBlast
Tool.Activated:Connect(function()
local Character = Tool.Parent
if Character then
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
local LoadedAnim = nil
if Humanoid.RigType == Enum.HumanoidRigType.R15 and AnimationR15 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR15)
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 and AnimationR6 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR6)
end
if LoadedAnim then
LoadedAnim:Play()
GunSound:Play()
wait(cooldown) -- attempting to play the cool down after the gun is shot
end
end
end
end)
Any help is appreciated! Thanks :)

2 comments
Isn't this method basically a debounce?
This didn't quite work, but I ended up using debounce and got it working! Thanks for getting me on the right track though!