I am trying to make a simple sword script and when I unequip the tool the animation is still stuck playing on my character. Here is the code:
local CanAttack = true
script.Parent.Equipped:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Hold)
local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack2)
idle:Play()
end)
script.Parent.Activated:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Hold)
local attack1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack1)
local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack2)
if CanAttack == true then
local attacks = {attack1, attack2}
local chosenattack = attacks[math.random(1, #attacks)]
chosenattack:Play()
idle:Stop()
CanAttack = false
wait(1)
chosenattack:Stop()
idle:Play()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)
script.Parent.Unequipped:Connect(function()
local idle = game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name).Humanoid:LoadAnimation(script.Hold)
idle:Stop()
end)