Animation not playing even tho Isplaying = true

Hello! i am trying to make a Animation Controller where i can control all the animations from a single module.

The issue is, the animation is not playing when i try play it from a certain function.

I have tried searching it up but have not found any solutions.

This is the Code i am using the load the animation to the player whilst adding it to an array:

function AnimationController:KnitStart()
	for i,v in next, AnimationStorage:GetDescendants() do
		if v:IsA('Animation') then
			local suc, anim = pcall(function()
				return Animator:LoadAnimation(v)
			end)
			
			if suc then
				LoadedAnimations[v.Name] = anim
			end
		end
	end
end;

And this is the code i am using to play the animation found in the array

function AnimationController.Play(Animation)
	local Name = Animation:lower()
	local Animation;
	
	for i,v in next, LoadedAnimations do
		if i:lower() == Name then
			Animation = v;
		end;
	end;
	
	repeat	Animation:Play(); 
	until Animation.IsPlaying == true;
	
	print(Animation.IsPlaying)
end;

Bizarre enough, when i put Anim:Play() under LoadedAnimations[v.Name] = anim (On the first code block of this post) the animation does play, but when i play it from the Play() function (The second block of code of this post) it does not play at all.

Thank you for all of your feedback, and have a lovely day!

Your issue is the repeat … until loop and possibly no Animator. Remove the loop and make sure you create and parent an Animator before loading animations. Example:

-- Setup
local animator = Instance.new("Animator")
animator.Parent = AnimatorParent -- Humanoid or AnimationController

for _, v in ipairs(AnimationStorage:GetDescendants()) do
    if v:IsA("Animation") then
        local track = animator:LoadAnimation(v)
        LoadedAnimations[v.Name] = track
    end
end

-- Play function
function AnimationController.Play(name)
    local track = LoadedAnimations[name]
    if not track then warn("Not found:", name) return end
    track:Play()
    print("IsPlaying:", track.IsPlaying)
end

Key points:

Always have a valid Animator.

Don’t block with repeat … until.

Confirm you call Play() from a LocalScript if animating a player.

1 Like