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"))
Output: 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()
Tool.Equipped:Connect(function()
local CharacterIdle = Character.Humanoid:LoadAnimation(script:WaitForChild("Idle"))
CharacterIdle:Play()
Tool.Unequipped:Connect(function()
CharacterIdle:Stop()
end)
end)
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.
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.
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)
animationPlay:Play()