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);
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?
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.