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

How do I make a cooldown for this animation script???

Hello! I have created a keybind roll script which plays an animation. However, I would like it to have a cooldown of like 1 second. Please provide the edited script as a reply. Script is below.

local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse()

local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=MYID"

mouse.KeyDown:connect(function(key) if key == "f" then local playAnim = humanoid:LoadAnimation(anim) playAnim:Play()

end

end)

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer 

repeat wait() until player.Character.Humanoid 

local CooldownSeconds = 2
local Debounce = true

local humanoid = player.Character.Humanoid 
local mouse = player:GetMouse()

local anim = Instance.new("Animation") 
anim.AnimationId = "http://www.roblox.com/asset/?id=MYID"

mouse.KeyDown:connect(function(key) if key == "f" and Debounce then
	Debounce = false 
	local playAnim = humanoid:LoadAnimation(anim) 
	playAnim:Play()
	wait(CooldownSeconds)
	Debounce = true
   end
end)

Hope this helps!

1 comment

0

It works! Thanks man!!!

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