Tool Animation Playing when unequipped?
I have this idle animation equipped in a tool, which plays the idle when equipped, then if I press W stops and when I release W plays again. But when I am pressing W and unequip the tool at the same time the animation keeps playing. I've tried adding some stuff but nothing is working so I turned to this
01 | local player = game.Players.LocalPlayer |
03 | repeat wait( 1 ) until player.Character |
05 | local character = player.Character |
06 | local humanoid = character:WaitForChild( "Humanoid" ) |
08 | local userInput = game:GetService( "UserInputService" ) |
10 | local animation = Instance.new( "Animation" ) |
11 | animation.Name = "Idle" |
12 | animation.Parent = script.Parent |
14 | local animation 2 = Instance.new( "Animation" ) |
15 | animation 2. Name = "Equip" |
16 | animation 2. Parent = script.Parent |
20 | local animtrack = humanoid:LoadAnimation(animation) |
23 | local animtrack 2 = humanoid:LoadAnimation(animation 2 ) |
24 | animtrack 2. Priority = Enum.AnimationPriority.Action |
25 | local tool = script.Parent |
27 | script.Parent.Equipped:connect( function () |
29 | script.Parent.Sound:Play() |
32 | script.Parent.Equipped:connect( function () |
35 | userInput.InputBegan:Connect( function (input) |
37 | if input.KeyCode = = Enum.KeyCode.W then |
43 | userInput.InputEnded:Connect( function (input) |
44 | if input.KeyCode = = Enum.KeyCode.W then |
46 | elseif tool.Unequipped = = true and input.KeyCode = = Enum.KeyCode.W then |
56 | script.Parent.Unequipped:connect( function () |
59 | userInput.InputEnded:Connect( function (input) |
60 | if input.KeyCode = = Enum.KeyCode.W then |