LoadAnimation Breaks on Respawn?

Hey DevForums, I made a tool in which, when you equip it, through a client script in the tool, an animation plays, stopping when you unequip. It works fine and all. But there’s one problem.

When I reset my character dies, and try to re-equip the tool, this line of code breaks:
local CharacterIdle = Character.Humanoid:LoadAnimation(script:WaitForChild("Idle"))

LoadAnimation requires the Humanoid object (abrah_m.Humanoid) to be a descendant of the game object

Local Script:

   local Tool = script.Parent

    local Player = game.Players.LocalPlayer
    local Character = Player.Character or Player.CharacterAdded:Wait()

    	local CharacterIdle = Character.Humanoid:LoadAnimation(script:WaitForChild("Idle"))

I’ve searched the DevForums with no avail.

I know your pain, I recently re-programmed a combat system I made, so it has a use of tools instead. I fixed my problem by keeping said tools in ServerStorage, and cloning them jnto the player’s backpack every time the player’s character loads. Keep in mind that if the tools aren’t in the players StarterPack, they will destroy after the player dies.

I already knew about this, but I just didn’t want to do it due to inefficiency.

At least it’s reliable to not break the code. Also, the code might be running before the assets appear. Create a separate variable for the humanoid, and wait for it to appear, then load the animation.

Maybe this could help?

replied to wrong person apologies

There is a new place in which you should load animations which is the child of the humanoid called “Animator”. Loading an animation into the animator is basically the same as the humanoid but a few extra steps, this may or may not fix some of your problems.

local animator = humanoid:FindFirstChildOfClass("Animator")
local animationPlay = animator:LoadAnimation(animation)