Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why isnt the idle animation stopping after unequipping the tool or moving?

Asked by 3 years ago
Edited 3 years ago

I've made a sword tool, and the animation wont stop playing when the tool is unequipped or when i'm running/jumping/falling etc.

script.Parent.Equipped:Connect(function()
    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local Equip = script.Parent.Parent.Humanoid:LoadAnimation(script.Equip)
    local EquipSound = script.EquipSound
    EquipSound:Play()
    Equip:Play()
    wait()
    Idle:Play()
end)

script.Parent.Unequipped:Connect(function()
    local Idle = script.Parent.Parent.Parent.Character.Humanoid:LoadAnimation(script.Idle)
    local Equip = script.Parent.Parent.Parent.Character.Humanoid:LoadAnimation(script.Equip)
    Idle:Stop()
    Equip:Play()
    script.Parent.Equip.Value = false
end)

script.Parent.Activated:Connect(function()
    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)   
    local Attack = script.Parent.Attack
    local AttackA =  script.Parent.Parent.Humanoid:LoadAnimation(script.AttackA)
    local AttackB =  script.Parent.Parent.Humanoid:LoadAnimation(script.AttackB)
    local AttackC =  script.Parent.Parent.Humanoid:LoadAnimation(script.AttackC)

    if Attack.Value == 1 and script.Parent.CanAttack.Value == true then
        AttackA:Play()
        Idle:Stop()
        script.AttackSound:Play()
        script.Parent.CanDamage.Value = true
        script.Parent.CanAttack.Value = false
        wait(0.5)
        script.Parent.CanAttack.Value = true
        Attack.Value = 2
        Idle:Play()
        script.Parent.CanDamage.Value = false


    else if Attack.Value == 2 and script.Parent.CanAttack.Value == true then
        AttackB:Play()
        Idle:Stop()
        script.AttackSound:Play()
        script.Parent.CanDamage.Value = true
        script.Parent.CanAttack.Value = false
        wait(0.5)
        script.Parent.CanAttack.Value = true
        Attack.Value = 3
        Idle:Play()
        script.Parent.CanDamage.Value = false


        else if Attack.Value == 3 and script.Parent.CanAttack.Value == true then
        AttackC:Play()
        Idle:Stop()
        script.AttackSound:Play()
        script.Parent.CanDamage.Value = true
        script.Parent.CanAttack.Value = false
        wait(0.5)
        script.Parent.CanAttack.Value = true
        Attack.Value = 1
        Idle:Play()
        script.Parent.CanDamage.Value = false
      end
    end
  end   
end)

1 answer

Log in to vote
0
Answered by
1JBird1 64
3 years ago

So I’m guessing this is in a server script

Before script.parent.Equipped:Connect(function() type down

local humanoid = nil

So inside of script.parent.Equipped:Connect(function() just add this right after the tool has been equipped

script.Parent.Equipped:Connect(function()
   humanoid = script.Parent.Parent:WaitForChild("Humanoid")
   -- code that you need
end)

and inside of the script.parent.Unequipped:Connect(function() type in:

script.parent.Unequipped:Connect(function()
   for i,anim in pairs(humanoid:GetPlayingAnimationTracks) do
      if anim.Animation.Animationid == "Insert_Idle_Animation_Id" then
         anim:Stop()
      end
   end
   equip:Play()
   script.Parent.Equip.Value = false
end)

hopefully this solves your problem :D

0
Thank you so much appreciated XD_Destroyer1234 4 — 3y
Ad

Answer this question