Im trying to make a function that stops all animations in a given table.
Though I’m not getting errors, the function does not work. It says that the animation is not playing even though it is. If i put print(animation.IsPlaying) it always comes out as false even if it is playing.
local function loadAnimation(animation_)
local track = animatior:LoadAnimation(tool:WaitForChild("Folder"):WaitForChild(animation_))
return track
end
local function playAnimation(Animation, play)
if play==true then
loadAnimation(Animation):Play()
elseif play==false then
loadAnimation(Animation):Stop()
end
end
local function stopStoredTracks1()
if animationFolder then
local animationTracks = animationFolder:GetChildren()
for _, tracks in pairs(animationTracks) do
for _,playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
if tracks:IsA("Animation") then
if tracks==playingTracks then
playingTracks:Stop()
else
end
end
end
end
end
end
You are confusing Animation instance and AnimationTracks. AnimationTracks are only returned from LoadAnimation() and you’re not saving the references, in this line: loadAnimation(Animation):Play()
you’re not saving the return value ‘track’. You have to either save the track references, or recover them later from Animator:GetPlayingAnimationTracks(). I prefer saving them to a table.
The children of your animationFolder are just Animation instances, which are not tracks, just wrappers for storing an AnimationId.
I tried doing what you said, but it still is not working. I probably did something wrong, this is what I did.
local trackTable={}
local function animTrackTable()
for i, anim in pairs(animationFolder:GetChildren()) do
if anim:IsA("Animation") then
table.insert(trackTable, animatior:LoadAnimation(animationFolder:WaitForChild(anim.Name)))
print("index:",tostring(i),"| animation name:",anim,"| class name:",animatior:LoadAnimation(animationFolder:WaitForChild(anim.Name)).ClassName)
end
end
end
local function stopStoredTracks1()
for _, track in pairs(trackTable) do
print(track.ClassName)
if track.IsPlaying then
track:Stop()
else
print("no")
end
end
end
Your debug print statement is creating a whole second set of AnimationTracks that don’t end up in trackTable. Don’t call LoadAnimation again just to get the class name, LoadAnimation only ever returns AnimationTracks so the class name is always going to be AnimationTrack anyways.
Second issue is that, at least in this latest code snippet, you’re never calling track:Play(), so IsPlaying is going to be false for all of the tracks. My expectation is that this code will just print “no” for each track in your table.