Anybody know how to stop animation if tool removed from player backpack?
local humanoid = nil
local char = nil
local player = nil
local rootPart = nil
local mouse = nil
local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local idleAnim = nil
local ForwardAnim = nil
local LeftAnim = nil
local RightAnim = nil
local wPressed = false
local sPressed = false
local aPressed = false
local dPressed = false
local spPressed = false
local equipped = false
local flying = false
script.Parent.Equipped:Connect(function()
humanoid = script.Parent.Parent.Humanoid
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
char = script.Parent.Parent
idleAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("IdleAnim"))
ForwardAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
RightAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
LeftAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
rootPart = script.Parent.Parent.HumanoidRootPart
mouse = player:GetMouse()
equipped = true
idleAnim:Play()
end)
script.Parent.Unequipped:Connect(function()
equipped = false
idleAnim:Stop()
ForwardAnim:Stop()
LeftAnim:Stop()
RightAnim:Stop()
end)
script.Parent.Remove:Connect(function()
equipped = false
idleAnim:Stop()
ForwardAnim:Stop()
LeftAnim:Stop()
RightAnim:Stop()
end)
uis.InputBegan:Connect(function(key, chat)
if equipped then
if chat then return end
if key.KeyCode == Enum.KeyCode.W and equipped == true then
wPressed = true
ForwardAnim:Play()
elseif key.KeyCode == Enum.KeyCode.S and equipped == true then
sPressed = true
ForwardAnim:Play()
elseif key.KeyCode == Enum.KeyCode.A and equipped == true then
aPressed = true
LeftAnim:Play()
elseif key.KeyCode == Enum.KeyCode.D and equipped == true then
dPressed = true
RightAnim:Play()
end
end
end)
uis.InputEnded:Connect(function(key, chat)
if chat then return end
if key.KeyCode == Enum.KeyCode.W then
wPressed = false
ForwardAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.S then
sPressed = false
ForwardAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.A then
aPressed = false
LeftAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.D then
dPressed = false
RightAnim:Stop()
end
end)

2 comments
It's my first question so it's so bad
Code block updated.