Okay normally I almost never have issues debugging and solving my own scripting problems, but this one I physically cannot figure out why it’s happening.
I’m making a simple tool with animiations using the Humanoid.Animator, and it seems to 100% work when i play test the game initially, but after resetting my character and then equipping the tool and loading the animation tracks a second time, I get this error:
This is really odd and I cannot for the life of me figure it out.
Some of my attempts to fix this mostly just include of my waiting for the character to fully load, or moving the LoadAnimiation() functions into the equip event, which neither of worked or made a difference.
Here is my code (LocalScript)
local Players = game:GetService("Players")
local Character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Tool = script.Parent
local Animations = Tool:WaitForChild("Animations")
local UseTrack
local IdleTrack
local EquipTrack
Tool.Equipped:Connect(function()
-- Load the animations
if not UseTrack then
UseTrack = Animator:LoadAnimation(Animations:WaitForChild("Use"))
IdleTrack = Animator:LoadAnimation(Animations:WaitForChild("Idle"))
EquipTrack = Animator:LoadAnimation(Animations:WaitForChild("Equip"))
end
EquipTrack:Play()
end)
Tool.Activated:Connect(function()
if Humanoid.Health > 0 then
UseTrack:Play()
end
end)
Tool.Unequipped:Connect(function()
EquipTrack:Stop()
IdleTrack:Stop()
UseTrack:Stop()
end)
I went down a rabbit hole of other people facing the same issue as you, dating back as far as February 2022. A lot of people seemed to have fixed this error message by making sure that whatever is loading the animation is a child of the workspace. So there is two possible options:
Whether these work I do not know for certain, but it is worth an attempt.
Option 1.
...
Tool.Equipped:Connect(function()
-- Load the animations
if not UseTrack then
Tool.Parent = game.Workspace
UseTrack = Animator:LoadAnimation(Animations:WaitForChild("Use"))
IdleTrack = Animator:LoadAnimation(Animations:WaitForChild("Idle"))
EquipTrack = Animator:LoadAnimation(Animations:WaitForChild("Equip"))
Tool.Parent = --<back to original position in the explorer>
end
...
Option 2.
...
Tool.Parent = game.Workspace
local UseTrack = Animator:LoadAnimation(Animations:WaitForChild("Use"))
local IdleTrack = Animator:LoadAnimation(Animations:WaitForChild("Idle"))
local EquipTrack = Animator:LoadAnimation(Animations:WaitForChild("Equip"))
Tool.Parent = --<back to original position in the explorer>
...
None of these solutions seem to solve anything. The tool is always a descendant of workspace when the animations get loaded, and nothing has changed from a typical animated tool.
And also it 100% works when you initially play test, but after respawning and trying to equip the tool, the error occurs. It’s a very unique problem.
These errors shouldn’t be happening in the first place, I have no idea why this is an issue now.
local Character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
Try this instead:
local Player = Players.LocalPlayer
local Character = Player.Character
if not (Character and Character.Parent then
Character = Player.CharacterAdded:Wait()
end
You need to check if the character is not the dead previous character that has been destroyed. LoadAnimation will fail if you try to load animations on one of these ‘dead’ characters.
I used to have the exact same problem and this was the solution.
Not sure when the code actually runs (I forgot how tool’s LocalScripts behave), is the problem possibly that these lines need to be re-run? I would try reseting these variables the function connected to Equipped just to see if that fixes it.