Is this a good way to do animations?

I’ve always been confused on how to properly handle and work with animations, but I’ve been trying to find a way that lets me easily just get a NPC and play or stop an animation and at first I thought this was good however I’m not too sure.

--Module Script
local Animations = game:GetService("ReplicatedStorage").Animations

Animation = {}
Animation.__index = Animation

function Animation:PlayAnimation(Animation)
	warn("PLAY ANIMATION")
	self.Amn[Animation]:Play()
end

function Animation:StopAnimation(Animation)
	warn("STOP ANIMATION")
	self.Amn[Animation]:Stop()
end

function Animation.new(Humanoid)
	local NewAnimation = {}
	setmetatable(NewAnimation,Animation)

	local Anims = {}
	if Animations then
		for _,anim in pairs(Animations:GetChildren()) do
			if anim:IsA("Animation") then
				Anims[anim.Name] = Humanoid:LoadAnimation(anim)
			end
		end
	end
	
	NewAnimation.Amn = Anims
	
	return NewAnimation
end

return Animation
--Localscript
local NPCFolder = workspace:WaitForChild("NPCs")

for _,NPC in pairs(NPCFolder:GetChildren()) do
	if NPC:FindFirstChild("Humanoid") then
		local Humanoid = NPC:FindFirstChild("Humanoid")
		_G[NPC.Name] = AnimationModule.new(Humanoid)
	end
end

--And then I could do this from anywhere
--_G."name of npc/model"
_G.Me:PlayAnimation("Idle") or _G.Me:StopAnimation("Idle")
2 Likes