Animation not playing on R15

Hi.

I can’t get the animations to play. I tried loading it on the Humanoid and AnimationController, even though that’s deprecated. No use. The AnimationID of ‘Idle’ is correct, and all the print statements are being executed as expected. What is wrong with my code?

This is running on a server-script only; does that have something to do with anything?

Thanks in advance.

local g: Instance = game;
local GS: (Instance, string) -> (any) = g['GetService'];


local WS: Workspace = GS(g, 'Workspace');


local Map = WS:WaitForChild('Map', 30.0);
local NPCs = Map['1st World']['1st Zone'].NPCs;



local function PlayAnimation(NPC: Model): ()
        print('a');
        local Animator = NPC.AnimationController:WaitForChild('Animator', 30.0);
        local Animation = NPC:WaitForChild('Idle', 30.0);
        print('b');
        local AnimationTrack = Animator:LoadAnimation(Animation);
        AnimationTrack.Priority = Enum.AnimationPriority.Idle;
        AnimationTrack.Looped = true;
        print('c');
        AnimationTrack:Play();
        print('d');
end



local Rig = NPCs.Bank.Rig;
PlayAnimation(Rig);

Was the animation done on a R15 rig? if not, then only the head would actually be animated.

1 Like

Yes it was, but, nevermind, it now works magically. I hate programming.

Now even if it works, it isn’t looping correctly. It ends. I know I can loop it through Animation.Ended:Connect() RBXScriptSignal, but is that good? Why is this even happening in the first place, again?

im pretty suire that “.Looped” (boolean) is a property of AnimationTrack.

It is, and I used it on an AnimationTrack instance as you can see in the above code.

oh i apologize, i didnt notice that. ill run the code with an animation of mine and see if i can find the problem

1 Like

Thanks. Yet, I found a workaround I don’t know if to use (I don’t think so, but may cause performance issues?). I just did:

AnimationTrack.Stopped:Connect(function(): ()
    AnimationTrack:Play(); -- for this to work, '.Looped' needs to be set to false. Otherwise the game deems the animation to never have 'stopped' (or 'ended' if you use '.Ended' event instead), and therefore, this is never called, the animation never being played once again.
end);

typically event connections are performance friendly, so you should be good. i dont use animations often so i have no idea why the other method wasnt working, but this seems like a fine workaround to me.

1 Like

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