Hey! I was making a roblox gun script that fires 1 bullet and takes 3 seconds before you can fire another, I made a animation to go along with it but when you wait for the bullet to load you can just spam the animation, is there a way to give this animation a cooldown? 
2 Likes
Have you tried wait()?
Maybe look for other methods like here and plug it in the script.
1 Like
You could just simply use a debounce, which would prevent the Animation from firing multiple times 
local DB = false
while true do
if DB == false then
print("This would only fire once every 5 seconds!")
DB = true
wait(5)
DB = false
end
end
3 Likes
where would I put this in my script?
where would I put this in my script though?
Put it inside where you call your Activated event, so that the conditional statement will check if the DB is equal to false or not to be able to set it to true once, preventing it from playing again
1 Like
local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = 'rbxassetid://6910396829'
local debounce = false
local track
tool.Activated:Connect(function()
if debounce == false then
debounce = true
track = script.Parent.Parent.Humanoid.Animator:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false
track:Play()
wait(3) -- the cooldown
debounce = false
end
end)
tool.Unequipped:Connect(function()
if track then
track:Stop()
end
end)
loading animations via the humanoid was deprecated im pretty sure, so its better to do humanoid.Animator
1 Like
Thank you all so much for the help! feels so good to see it working how I intended!
1 Like