Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this error occur with LoadAnimation()?

Asked by
Mineloxer 187
7 years ago

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 :)

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? unmiss 337 — 7y
0
That didn't seem to work, still gave me the same error: Mineloxer 187 — 7y

1 answer

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
7 years ago

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
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. Mineloxer 187 — 7y
0
The only other explanation is that the character isn't loading or is being destroyed immediately. 2eggnog 981 — 7y
0
Alright, I will try to make a script that disables, then renables it. Thanks :) Mineloxer 187 — 7y
Ad

Answer this question