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

Why did I got a LoadAnimation Descendant Error while loading an animation?

Asked by 6 years ago
Edited 6 years ago

The script works well in the Studio and Test Server, but when I decided to publish It, I got "LoadAnimation requires the Humanoid object (FlonexVorry.Humanoid) to be a descendant of the game object" error. Please help me, what should I do in order to make my script works?

Tool = script.Parent.Parent
repeat wait() until game.Players.LocalPlayer.Character
local char = game.Players.LocalPlayer.Character
local humanoid = char:WaitForChild("Humanoid")
local ButtonPressed = false
local Attacking = script.Parent.IsAttacking.Value
local Animation = script.Parent.Parent.Animations:WaitForChild("Attack")

Tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()
----------------------------------------------------------------------  
            if not ButtonPressed then
                ButtonPressed = true
                x = humanoid:LoadAnimation(Animation)
                x:Play()
                wait(1)
                ButtonPressed = false
            end
---------------------------------------------------------------------
    end)
end)
0
Very weird, I would guess it's a problem with another script, not sure though User#20388 0 — 6y

2 answers

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago

Weird error. Try this out:

repeat wait() until game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(workspace)

Tool = script.Parent.Parent

local Player = game.Players:WaitForChild(game.Players.LocalPlayer.Name)
local Character = Player.Character
local Humanoid = nil 

local ButtonPressed = false

local Attacking = script.Parent.IsAttacking.Value
local Animation = script.Parent.Parent.Animations:WaitForChild("Attack")
local Track = nil 

function getHumanoid(character)
    if character then 
        for _, v in pairs(character:GetChildren()) do 
            if v:IsA('Humanoid') then 
                Humanoid = v
                print("Found " .. Humanoid.Name)
            end
        end
    end
end

Tool.Equipped:connect(function(Mouse)
    getHumanoid(Character)
    Mouse.Button1Down:connect(function()
----------------------------------------------------------------------  
            if not ButtonPressed then
                ButtonPressed = true
                Track = Humanoid:LoadAnimation(Animation)
        Track:Play()
                wait(1)
                ButtonPressed = false
            end
---------------------------------------------------------------------
    end)
end)

Ad
Log in to vote
0
Answered by
Galicate 106
6 years ago

I HAVE THE ANSWER. OK so you are referencing the character before the character is loading, scripts usually run before the character has loaded in. My solution is to put a wait(2) before line 03.

Answer this question