Is This an Efficient Way to Handle Animations?

So I’ve been using a system for loading in and playing animations, and I wanted to check if it’s a reliable way to do so, or if there’s something more efficient that could be done.

Basically the following code would be placed into a module script,

local AnimationPackages = {
	
	
	["HumanAnimations"] = {
		Idle = "Some Animation Instance";
		Walk = "Some Animation Instance";
	};
	
	
	["DogAnimations"] = {
		Idle = "Some Animation Instance";
		Walk = "Some Animation Instance";
	};
	
	
	["CatAnimations"] = {
		Idle = "Some Animation Instance";
		Walk = "Some Animation Instance";
	};
	
	
}



function Module.getAnimations(AnimType, PlrAnimator)
	local AnimationTable = {}
	
	for Type, Animation in pairs(AnimationPackages) do
		
		AnimationTable[Type] = PlrAnimator:LoadAnimation(Animation)
		
	end
	
	return AnimationTable
end

Then called from another script, Module.getAnimations("HumanAnimations, Humanoid.Animator") which would return an “Animation Table” full of loaded animations that can be used like so,

AnimationTable["Idle"]:Play()

AnimationTable["Walk"]:Stop()

It seems like a pretty convieniet way for handling animations to me, but as I said previously I’d like to make sure there’s not any adverse practices, or cringe worthy code. I use this system for pretty much everything that requires to be animated, Weapons, NPCs, Items, etc.

1 Like

Looks fine to me, might have some performance issues if theres alot of animations in the table though.

1 Like

You should store the ids rather than instances and let the client or server create the instance on their own.

1 Like

Oh, alright. I thought it would have been better to just have 1 copy of everything, but I can go that route. Thanks for the help!

1 Like