I'm trying to stop an animation after the tool gets unequipped but the animation still sticks around being a burden on the regular walking animation. I'm not sure what to do.
local Gun = script.Parent
local Handle = Gun:WaitForChild("Handle")
local Event = Gun: WaitForChild("RemoteEvent")
local Swing = Instance.new("Animation",script.Parent)
local Equip = Instance.new("Animation", script.Parent)
local CanFire = true
Swing.AnimationId = "http://www.roblox.com/Asset?ID=700778123"
Equip.AnimationId = "http://www.roblox.com/Asset?ID=700657273"
FireRate = 1
local trackanimation = nil
local trackanimation2 = nil
function playAnimation(Anim)
local plr = game.Players.LocalPlayer
trackanimation = plr.Character.Humanoid:LoadAnimation(Anim)
trackanimation.KeyframeReached:Connect(function(kf)print("Working")end)
trackanimation:Play()
end
function playAnimation2(Anim)
local plr = game.Players.LocalPlayer
trackanimation2 = plr.Character.Humanoid:LoadAnimation(Anim)
trackanimation2.KeyframeReached:Connect(function(kf)print("Working")end)
trackanimation2:Play()
end
Gun.Equipped:Connect(function(Mouse)
if Mouse then
playAnimation(Equip) --Play the equip animation
Mouse.Button1Down:Connect(function()
playAnimation2(Swing) --Play the animation for swining
if CanFire then
CanFire=false
playAnimation(Swing)
print("Firing")
Event:FireServer("Fire", Mouse.Target)
wait(FireRate)
CanFire=true
end
end)
end
end)
Gun.Unequipped:Connect(function(Mouse)
local plr = game.Players.LocalPlayer
plr.Character.Humanoid:LoadAnimation(Equip):Stop()
plr.Character.Humanoid:LoadAnimation(Swing):Stop()
end)
Here is a link of it happening. I apologize if this script is a mess, I just learned animating a few hours ago.

1 comment
Still does the same thing as before.