So I was looking for a tutorial on how to make cooldowns after clicking. Like wait(1) after a punch but I was too specific and couldn't find any. Here's the local script, and tell me instructions.
Local script:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")
tool.Equipped:connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
idle:Play()
end)
tool.Activated:connect(function()
local choose = math.random(1,2)
canattack.Value = true
if choose == 1 then
local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
swingsound:Play()
swing1animation:Play()
elseif choose == 2 then
local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
swingsound:Play()
swing2animation:Play()
end
end)
tool.Deactivated:connect(function()
canattack.Value = false
end)
tool.Unequipped:connect(function()
local hum = char:WaitForChild("Humanoid")
for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
anim:Stop()
end
end)

1 comment
CanAttack is a bool value