LoadAnimation requires the Humanoid object to be a descendant of the game object

Hey,

I’m working on a gun system for my game, and whenever the player spawns with the gun, I get the error LoadAnimation requires the Humanoid object to be a descendant of the game object even when the character parent is not nil. If the player immediately spawns with the weapon, the script returns that error, but if the player spawns and then get the weapon after a few seconds (I tested using admin commands to give myself the gun after spawning) it works perfectly normal.

Yes, I already searched for solutions and I did find other topics about this, but none of them resolved my issue. I tried using the code available in the following post but it didn’t work and just made my script
infinitely loop.

My current code:

[...]

if not player.Character then player.CharacterAdded:Wait() end -- No errors

local humanoid = player.Character:FindFirstChild('Humanoid') -- No errors

if player.Character.Parent ~= game.Workspace then repeat wait() until player.Character.Parent == game.Workspace end -- No errors

local HoldTrack = humanoid:LoadAnimation(AnimHold) -- Error: LoadAnimation requires the Humanoid object (VinBR205.Humanoid) to be a descendant of the game object
local HolsterTrack = humanoid:LoadAnimation(AnimHolster)
local ReloadTrack = humanoid:LoadAnimation(AnimReload)
local EquipTrack = humanoid:LoadAnimation(AnimEquip)
local HolsteringTrack = humanoid:LoadAnimation(AnimHolstering)
local CrouchingTrack = humanoid:LoadAnimation(AnimCrouching)
local CrouchedTrack = humanoid:LoadAnimation(AnimCrouched)

How can I stop the error from being triggered and actually make the animations load?

Humanoid:LoadAnimation() is now deprecated. Use Animator:LoadAnimation(), a child of the player’s Humanoid instead.

3 Likes