Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this error occur with LoadAnimation()?

This script is inside a tool, in the StarterPack. It works fine the first time it runs, but when I reset, It gives the following error:

00:54:25.724 - LoadAnimation requires the Humanoid object (Player1.Humanoid) to be a descendant of the game object

I am using Filtering enabled/Non-experimental mode, so I suspect the issue is from it, since this only happens in the client/in game but not in the Studio

--//This script handles the animation and functionality
--//Variables\\--
local Tool = script.Parent.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Mouse = Player:GetMouse()
local Humanoid = Character:WaitForChild("Humanoid")
local AnimFolder = Tool:WaitForChild("Animations")
local Storage = game.ReplicatedStorage
local EventsFolder = Storage:WaitForChild("Events")
local FunctionsFolder = Storage:WaitForChild("Functions")

--//Remote Events\\--
--//Animations\\--
local HoldAnimation = AnimFolder:WaitForChild("Hold")
local SwingAnimation = AnimFolder:WaitForChild("Swing")

--//Animation Tracks\\--
repeat wait() until Character.Humanoid
print(tostring(Humanoid), typeof(Humanoid)) --For debugging
local HoldTrack = Humanoid:LoadAnimation(HoldAnimation) --Error occurs here
local SwingTrack = Humanoid:LoadAnimation(SwingAnimation) --And here

--//Events\\--
Tool.Equipped:connect(function()
	HoldTrack:Play()
	Tool.Activated:connect(function()
		SwingTrack:Play()
	end)
end)

Tool.Unequipped:connect(function()
	HoldTrack:Stop()
	SwingTrack:Stop()
end)

Roblox Forums didn't help one bit, so I expect people here would be more helpful Thanks in advance :)

2 comments

0

It has nothing to do with FilteringEnabled. In fact, you're supposed to run Animations on the client. Could you try adding FindFirstChild onto line 19?

0

That didn't seem to work, still gave me the same error:

1 answer

The CharacterAdded event fires before the character has been added to the workspace. Add the following line before you run LoadAnimation.

repeat wait() until Character.Parent

3 comments

0

I tried that, but now it doesn't go past that line. I have also noticed something, when the scripts breaks, a quick disable then enable makes it restart and work again.

0

The only other explanation is that the character isn't loading or is being destroyed immediately.

0

Alright, I will try to make a script that disables, then renables it. Thanks :)

This discussion is preserved as it was. New answers, comments, and votes are closed.