I have a tool where once you equip it, an animation plays. But for some odd reason, when you unequip it, it doesn’t stop the animation track. Help please, here’s the script.
local tool = script.Parent
local sound = tool.Handle.Sound
local idleanim = Instance.new(“Animation”)
idleanim.AnimationId = “rbxassetid://5743938093”
local track1
local shootanim = Instance.new(“Animation”)
shootanim.AnimationId = “rbxassetid://5736412338”
local track2
Try putting each function separate from each other, for what i can see in the script all of the functions are inside of tool.Equipped:Connect(function().
That probably happened cause you need to activate the tool in order to assing the track2 variable to the animation. You can use an if statement to make sure trak2 is not nil
Put track1 = script.Parent.Parent.Humanoid:LoadAnimation(idleanim) outside of Equipped and Put track2 = track2 = script.Parent.Parent.Humanoid:LoadAnimation(shootanim) outside Activated and it should work.
This is caused when you track1 and track2 in the function instead of it being outside of it.
local tool = script.Parent
local sound = tool.Handle.Sound
local idleanim = Instance.new(“Animation”)
idleanim.AnimationId = “rbxassetid://5743938093”
local track1 = script.Parent.Parent.Humanoid:LoadAnimation(idleanim)
local shootanim = Instance.new(“Animation”)
shootanim.AnimationId = “rbxassetid://5736412338”
local track2 = script.Parent.Parent.Humanoid:LoadAnimation(shootanim)
tool.Equipped:Connect(function()
track1.Priority = Enum.AnimationPriority.Movement
track1.Looped = true
track1:Play()
tool.Activated:Connect(function()
track2.Priority = Enum.AnimationPriority.Movement
track2.Looped = false
track2:Play()
wait(.5)
sound:Play()
tool.Unequipped:Connect(function()
track2:Stop()
track1:Stop()
end)
end)
end)