How do I store animation tracks in a module script?

I’m trying to load animations tracks into a module script so I can require the animations instead of loading them individually every time.

This is the code I have in a local script, not module script.

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animationIds = {
	["swordIdle"] = "rbxassetid://", --insert ID here, filled in already in studio
	["swordM1"] = "rbxassetid://" --insert ID here, filled in already in studio
}

local animationTrack = {}

for i,v in animationIds do
	local animation = Instance.new("Animation")
	animation.Name = i
	animation.AnimationId = v
	animationTrack[animation.Name] = humanoid.Animator:LoadAnimation(animation)
end

What I don’t understand is how I am going to load an animation track if it requires the humanoid.
There’s this forum post, but it never fully answers it.

2 Likes

Has your Module thrown an error? And if so, was it the same error that was thrown for the person that made the post you provided the link for? Or are you being cautious because of that post?

I was being too cautious. It works.

Requiring the module script does get the humanoid. Not sure how it works though.

If I were to guess how it works, requiring module scripts would insert everything in it to the script.

1 Like

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