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

Why does animation still play when tool unequips?

Asked by 3 years ago
Edited 3 years ago

I want to make it where when i equip a tool a animation plays, and when i unequip it, the animation should stop. When i unequip it, the animation still plays.

help

local Tool = script.Parent
local Animation = Tool.Animation





Tool.Equipped:Connect(function()

    local Player = Tool.Parent
    local Humanoid = Player.Humanoid
    local Animator = Instance.new("Animator")

    local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

    AnimationPlay:Play()


end)


Tool.Unequipped:Connect(function()

    local Player = Tool.Parent
    local Humanoid = Player.Humanoid
    local Animator = Instance.new("Animator")


    local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

    AnimationPlay:Stop()

end)

1 answer

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

instead of:

local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

AnimationPlay:Stop()

try:

for i,child in pairs(Humanoid:GetPlayingAnimationTracks()) do
 if child.Animation.AnimationId == “rbxasset//insert_animation_id” then
  child:Stop()
 end
end

hopefully it works out :D

Ad

Answer this question