I cant play a loaded animation from a different script(Help)

So i have a script where i loaded my animation and i want to play the animation from another script.
first script:

self.ChildAdded:Connect(function(c)
	
	if c:IsA("Tool") then
		for i,v in pairs(c:GetDescendants()) do
			if v:IsA("Animation") then
				ActionAnims[tostring(v.Name)] = Humanoid.Animator:LoadAnimation(v)
			end
		end
	end
end)

And part of the other script:

if tool.Parent and tool.Parent:FindFirstChildOfClass("Humanoid") and tool.Parent.Humanoid.Health > 0 and tool.Parent.Humanoid:FindFirstChildOfClass("Animator") then
		local loadedAnimations = 
        tool.Parent.Humanoid:FindFirstChildOfClass("Animator"):GetPlayingAnimationTracks()
		
		for	i,v in pairs(loadedAnimations) do
            print(v.Animation.AnimationId)
			print(tool.Aim.AnimationId)
			print(3)
			if v.Animation.AnimationId == tool.Aim.AnimationId then
				v.Animation:Play()
			end
			
		end
		
		
		isEquipped = true
		
	end
end

Why is it not showing the animation i loaded from the first script in the other script?

Because :GetPlayingAnimationTracks is only for currently playing animation tracks, these are not playing, so you should simply use a ModuleScript for loading and returning all of these animation tracks

Actually i found another way.

What i did on the first script is Play() all the loaded animations then stop() them

self.ChildAdded:Connect(function(c)
	if pose == "Dead" then
		return
	end
	if c:IsA("Tool") then
		for i,v in pairs(c:GetDescendants()) do
			if v:IsA("Animation") then
				ActionAnims[tostring(v.Name)] = Humanoid.Animator:LoadAnimation(v)
				ActionAnims[tostring(v.Name)]:Play(0,1,0)
				ActionAnims[tostring(v.Name)]:Stop()
			end
		end
	end
end)

the i could freely play them on the other script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.