LoadAnimation requires Humanoid object to be a descendant of workspace?

I have a punch tool that works entirely except when I use a randomized starter character. I have a script that chooses a random startercharacter from server storage, but when the tool is being used by one of these characters it does not load the attack animations and gives me an error message in output: “LoadAnimation requires the Humanoid object (boilinglogan8765432.Humanoid) to be a descendant of the game object”

What is the problem here and how might I be able to fix it?

image

image

The random character script:

	while wait(0.5) do
	local GenRand = math.random(1,3)

		if GenRand == 1 then
			game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
			game.ServerStorage.Char1.StarterCharacter:Clone().Parent = game.StarterPlayer

			
			
		elseif GenRand == 2 then
			game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
			game.ServerStorage.Char2.StarterCharacter:Clone().Parent = game.StarterPlayer
			
			
			
		elseif GenRand == 3 then
			game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
			game.ServerStorage.Char4.StarterCharacter:Clone().Parent = game.StarterPlayer
			
			
				end
		end

the tool script:

local humanoid = char:WaitForChild("Humanoid")
local Holding = script:WaitForChild("Holding")


local anim = script:WaitForChild("Punch")
local anim1 = script:WaitForChild("PunchReady1")
local anim2 = script:WaitForChild("PunchLaunch")
local anim3 = script:WaitForChild("PunchHold")


local Punchdo = humanoid:LoadAnimation(anim)
local PunchReady = humanoid:LoadAnimation(anim1)
local PunchLaunch = humanoid:LoadAnimation(anim2)
local PunchHold = humanoid:LoadAnimation(anim3)

local debounce = false

script.Parent.Activated:Connect(function()	
		if debounce == true then
		return	
	end
			Holding.Value = true			
		PunchReady:Play()
	PunchReady.Stopped:Wait()
		PunchHold:Play()
end)

script.Parent.Deactivated:Connect(function()
	if debounce == true then 
			return
	end		
			debounce = true
	Holding.Value = false
	PunchHold:Stop()
	PunchLaunch:Play()
			wait (2)	
		debounce = false
	end)

![2021-08-08 12-38-56|video](upload://xQ8TUeRxxcPrq9GL9nten5uDQZS.mp4)

You didn’t defy the character in the animation script

How would I define the character?

It depends. Is the tool script local?

Yes. The tool is a local script.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid

I put the definitions in the script and nothing changed.

Oh my bad do
local humanoid = Character.Humanoid

would
local humanoid = char:WaitForChild(“Humanoid”) or char.Humanoid
work as well?

local humanoid = char:WaitForChild("Humanoid") is better to use because if the humanoid isnt loaded yet, the script will wait until the humanoid is loaded. And the humanoid wont return nil so yea

That is exactly what I have in the script… I can’t tell what is wrong with it.

Try using this code for your tool script (just a few changes were made):

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local anim = script:WaitForChild("Punch")
local anim1 = script:WaitForChild("PunchReady1")
local anim2 = script:WaitForChild("PunchLaunch")
local anim3 = script:WaitForChild("PunchHold")


local Punchdo = hum:LoadAnimation(anim)
local PunchReady = hum:LoadAnimation(anim1)
local PunchLaunch = hum:LoadAnimation(anim2)
local PunchHold = hum:LoadAnimation(anim3)

local debounce = false

script.Parent.Activated:Connect(function()	
	if debounce == true then
		return	
	end

	Holding.Value = true			
	PunchReady:Play()
	PunchReady.Stopped:Wait()
	PunchHold:Play()
end)

script.Parent.Deactivated:Connect(function()
	if debounce == true then 
		return
	end		

	debounce = true
	Holding.Value = false
	PunchHold:Stop()
	PunchLaunch:Play()
	wait(2)	
	debounce = false
end)

Now it’s having the error I had before and “Players.boilinglogan8765432.Backpack.BabyNinjaTime Fist.LocalScript:11: attempt to index nil with ‘LoadAnimation’”

hmm… Do you really need a local script for playing the animations? I think it would be better if you’d do this on a (server) Script instead of a LocalScript.

The problem here could be the animations themselves

1 Like

The animations work until I reset my character to activate the random character script.

Ive had this type of issue before. I was trying to play animations on a local script, and it gave me that error (thats said in the topic name). But I fixed it by playing the animations on a server script.
So no, i dont think it has anything to do with the animations themselves.

Wait, I forgot to change humanoid to hum in the code i provided above. I just edited the code, try using that code again above (in a local script).

I am putting your script into 2 different tools, one that uses local scripts, and one that uses normal scripts.

1 Like