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

How to add delay on animations?

I tried making an animation for my tool and it worked. But, I want to make it so that is has a 5 seconds cooldown.. help pls

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
		animation:Play()
	end)
end)

script.Parent.Unequipped:Connect(function()
	animation:Stop()
end)

1 comment

0

When are you looking for it to cooldown? Before you unequip or during unequipped?

1 answer

✓ Accepted answer

For that, you should use debounce! It's quite a simple concept firstly you want to create a variable call it debounce or cooldown anything really! And make the variable false. I'm not too sure about what you are asking, if you are trying to achieve a cooldown on your equip/unequip or just animation from what I understand you are asking for animation so here are the building blocks.

local cooldown = false
local cooldownTime = 5 -- cooldown seconds

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if cooldown == false then -- checks if its not on cooldown
			cooldown = true -- sets to cooldown
			animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
			animation:Play()

		elseif cooldown == true then -- if its on cooldown it waits cooldownTime and sets false
			wait(cooldownTime)
			cooldown = false
		end
	end)
end)

script.Parent.Unequipped:Connect(function()
	animation:Stop()
end)

Questions concerns and bugs, just comment!

1 comment

0

Tested and is exactly what I wanted TYSM!!!!! :DD

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