Automatically get all animation tracks and add them to table

So I’m working on a port of my friend’s game, and I want do very simple animation tables which don’t require that much effort. So, let me explain a scene

the character’s root part contains animation tracks, I want these animation tracks to be organized into a table in a format like this

Animations = {
["idle"] = Player.Character:LoadAnimation(location),
}

How would I begin writing a script which automatically fills it like this so I can easily just
Animations[“idle”]:Play()
and
Animations[“idle”]:Stop()

My brain isn’t working much and I’m not SUPER familiar with Tables.

I tried something like this but it didn’t work.

for i,v in pairs(stand.StandHumanoidRootPart:GetChildren()) do
	if v:IsA("AnimationTrack") then
		table.insert(Animations,tostring(v), Player.Character.Humanoid:LoadAnimation(v))
	end
end

You should use character.Humanoid.Animator:LoadAnimation() instead of character:LoadAnimation()
and the way to do this is have an animations table with all the anim instances and then load them with a for loop like this

local animTable = {"GroundSmash" = tool.Animations["GroundSmash"]}

function LoadAnimations(animator,animTable)
	local AnimTracks = {}

	for i,v in pairs(animTable:GetChildren()) do
		AnimTracks[v.Name] = animator:LoadAnimation(v)
	end

	return AnimTracks
end

local AnimTracks = LoadAnimations(char.Humanoid.Animator,animTable)
print(AnimTracks)

and you should get something like this
image

so now to use it you can just do

AnimTracks["GroundSmash"]:Play()
3 Likes