My animations will not load

Whenever I run this script, I get this error

[16:23:26.185 - LoadAnimation requires the Humanoid object (Dracolyx.Humanoid) to be a descendant of the game object

script:

local Player = script.Parent.Parent.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Animations = {
	[1] = "rbxassetid://4801147006",
	[2] = "rbxassetid://4801266090",
	[3] = "rbxassetid://4801373074",
	[4] = "rbxassetid://4801418919",
}

local tracks = {
}

for num,animation in pairs(Animations) do
	local anim = Instance.new("Animation")
	anim.AnimationId = animation
	Humanoid:LoadAnimation(anim)
	local track = Humanoid:LoadAnimation(anim)
	tracks[num] = track
end

For one, you’re loading the animations twice which is unnecessary.
Secondly, try using table.insert(tracks, track)

This will insert it in counted order, but it’ll act the same.
To index the first animation after so for example, use:
tracks[1]:Play()

Forgot to mention in post 1, but instead of doing that, you can set up a function to handle all of that.

local function loadAnimation(animationId)
    local animationInstance = Instance.new("Animation")
    animationInstance.AnimationId = animationId
    return humanoid:LoadAnimation(animationInstance) -- assumptively you have the humanoid defined.
end

loadAnimation(1):Play() -- 1 is an example.

This code is untested, but should theoretically work.

The error is a loading issue, I just want to know how to fix this loading error. Apparently the Humanoid has not loaded yet, though it has a WaitForChild slapped on it.

You did not run the Animation, to do so add “track:Play()” under the animation track variable.

In that case, I recommend adding AnimationTrack into the script and put the IDs from properties, the script could have loading issues.

Not adding a timeout to the WaitForChild(name, timeout) will result in a infinite yield warning.
Try adding a time, after so, check if the humanoid exists.

If not, create the humanoid.

Example;

local humanoid = character:WaitForChild("Humanoid", 1) -- 1 is the time out, estimated in seconds.

if (humanoid ~= nil) then
    -- Do whatever here, i.e load the animations and whatnot.
elseif (humanoid == nil) then
    humanoid = Instance.new("Humanoid")
    local animator = Instance.new("Animator") -- this is the instance that replicates your animations you load.
    humanoid.Parent = character
    animator.Parent = humanoid
    
    -- Load animations here.
end