I solved this by putting local animTrack = hum:LoadAnimation(script.Idle) outside of the functions
I've got a tool that is a weight, the player equips it, it plays an animation that is on loop (to make it look like it's being held), plays an animation when it's clicked, and is suppose to stop playing the animation that is looped when it's unequipped. It wont stop the animation though, any ideas why? Maybe because I'm trying to stop an animation that was defined in a different function? I'm not sure. Here's my script (local script in tool):
local Weight = script.Parent.Handle
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
Player.CharacterAdded:connect(function(character)
char = character
hum = char:WaitForChild("Humanoid")
end)
if not hum.Parent then
repeat wait(0.2) until hum.Parent
end
function Hold()
local animTrack = hum:LoadAnimation(script.Idle)
animTrack:Play()
end
function Lift()
local animTrack2 = hum:LoadAnimation(script.Lift)
animTrack2:Play()
end
function StopHold()
local animTrack = hum:LoadAnimation(script.Idle)
animTrack:Stop()
end
script.Parent.Equipped:connect(Hold)
script.Parent.Activated:connect(Lift)
script.Parent.Unequipped:connect(StopHold)
