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

How can I stop my Idle animation?

Asked by
TheePBHST 154
5 years ago

So, when I equip my tool it works perfectly but then when I unequip it, the animation stays and doesn't end/stop. The animation I've made is two. One is the equip, and the other one, where it stays/idle. It should stop from what I've placed but it doesn't.

Note: The second one/idle is a loop so the animation doesn't stop until :Stop() is fired

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local EquipAnim  
local IdleAnim

script.Parent.Equipped:Connect(function()
    if Player.Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
        EquipAnim = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.EquipR15)
        EquipAnim.Priority = Enum.AnimationPriority.Action
        wait()
        EquipAnim:Play()

        EquipAnim.Stopped:Connect(function()
            IdleAnim = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.IdleR15)
            IdleAnim.Priority = Enum.AnimationPriority.Action
            IdleAnim:Play()
        end)
    elseif Player.Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
        EquipAnim = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.EquipR6)
        EquipAnim.Priority = Enum.AnimationPriority.Action
        wait()
        EquipAnim:Play()

        EquipAnim.Stopped:Connect(function()
            IdleAnim = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.IdleR6)
            IdleAnim.Priority = Enum.AnimationPriority.Action
            IdleAnim:Play()
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    EquipAnim:Stop()
    wait()
    IdleAnim:Stop()
    EquipAnim = nil
    IdleAnim = nil 
end)

script.Parent.Deactivated:Connect(function()
    --
end)

Answer this question