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

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

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)

1 comment

0

Very weird, I would guess it's a problem with another script, not sure though

2 answers

✓ Accepted answer

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)

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.

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