LoadAnimation requires the Humanoid object to be a descendant of the game object

hello i’m making a simple gun with the body attach for 100% animated tool when i first spawn its working fine but when i die it says

 LoadAnimation requires the Humanoid object (322ita.Humanoid) to be a descendant of the game object

here is the script

   local canshoot = true
local isreloading = false
local noammotime = true
local holding = false
local canreload = true

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local tool = script.Parent

local actionService = game:GetService("ContextActionService")

local hum

local shootEff
local equipeff
local reloadeff
local emptyeff

local variables
local ammo
local reserveammo
local magsize

local playerGui
local show_ammo

local idleAnim
local shootAnim
local reloadAnim
local emptyanim


local function reload()
	
	if canreload ==true and holding == true and isreloading == false and reserveammo.Value > 30 and ammo.Value < 30 then
		local needed = magsize.Value - ammo.Value
		wait()
		isreloading = true
		canreload = false
		reloadAnim:Play()
		reloadeff:Play()
		wait(3)
		isreloading = false
		ammo.Value = magsize.Value
		wait()
		reserveammo.Value = reserveammo.Value - needed
		canreload = true
		
	elseif canreload ==true and reserveammo.Value < 30 or reserveammo.Value == 30 and holding == true and isreloading == false and ammo.Value < 30 then
		local needed = ammo.Value + reserveammo.Value
		wait()
		isreloading = true
		canreload = false
		reloadAnim:Play()
		reloadeff:Play()
		wait(3)
		isreloading = false
		ammo.Value = ammo.Value + needed
		wait()
		reserveammo.Value = reserveammo.Value - needed
		canreload = true
		
	elseif	 reserveammo.Value < 0 then
		canreload = false
	end
end




tool.Equipped:Connect(function()
	
		hum = char:WaitForChild("Humanoid")
	 shootEff = tool:WaitForChild("Hole"):WaitForChild("shoot")
	 equipeff = tool:WaitForChild("Hole"):WaitForChild("Equip sound")
	 reloadeff = tool:WaitForChild("Hole"):WaitForChild("Reload Sound")
	 emptyeff = tool:WaitForChild("Hole"):WaitForChild("EmptySound")

	 variables = tool:WaitForChild("VALues")
	 ammo = variables:WaitForChild("ammo")
	 reserveammo = variables:WaitForChild("reserveammo")
	 magsize = variables:WaitForChild("MagSize")

	 playerGui = plr:WaitForChild("PlayerGui")
	 show_ammo = playerGui:WaitForChild("show ammo")

	idleAnim = hum:LoadAnimation(script:WaitForChild("Hold"))
	shootAnim = hum:LoadAnimation(script:WaitForChild("Recoil"))
	reloadAnim = hum:LoadAnimation(script:WaitForChild("Reload"))
	emptyanim = hum:LoadAnimation(script:WaitForChild("empty"))
	
	show_ammo.Enabled = true

	actionService:BindAction("Reload", reload, true, Enum.KeyCode.R)
	actionService:SetPosition("Reload", UDim2.new(0.58, 0,0.15, 0))
	actionService:SetTitle("Reload", "reload")
	local mouse = game.Players.LocalPlayer:GetMouse()
	mouse.Icon = "http://www.roblox.com/asset?id=117431027"

	game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)

	char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
	char.UpperTorso.ToolGrip.Part1 = tool.BodyAttach


	idleAnim:Play()
	equipeff:Play()
	holding = true
	while wait() do

		show_ammo.TextLabel.Text = "ammo: "..ammo.Value.."/ "..reserveammo.Value
	end
	
end)

tool.Unequipped:Connect(function()
	show_ammo.Enabled = false
	actionService:UnbindAction("Reload")
	local mouse = game.Players.LocalPlayer:GetMouse()
	mouse.Icon = "http://www.roblox.com/asset?id=5801470647"

	game.ReplicatedStorage.DisconnectM6D:FireServer()

	idleAnim:Stop()
	equipeff:Play()
	holding = false
end)



tool.Activated:Connect(function()
	
	if isreloading == false and ammo.Value > 0 and canshoot == true then
		wait()
		ammo.Value = ammo.Value - 1
		canshoot = false
		shootAnim:Play()
		shootEff:Play()
		wait(1)
		canshoot = true
	elseif ammo.Value == 0 and noammotime == true then
		local playerGui = plr:WaitForChild("PlayerGui")
		playerGui["no ammo"].Enabled = true
		noammotime = false
		emptyeff:Play()
		emptyanim:Play()
		wait(3)
		noammotime = true
		playerGui["no ammo"].Enabled = false
		
	end
		

end)




i’ve already did some reserach but i didnt find any fix can some one help me?

1 Like

most likely a problem with the line:

hum = char:WaitForChild("Humanoid")

since it will just yield waiting for a new humanoid, instead you can do:

hum = char:FindFirstChild("Humanoid") or char:WaitForChild("Humanoid")

nop it dosent work sadly, im getting the same error

rather than changing the hum variable to the actual object when the tools equipped, why not set it at the start of the script?

i’ve already tried it it still dosent work, maybe i’ll try putting all the variables at the start

You should really be using the Animator (Animator) Loading animations into a humanoid is deprecated:

2 Likes

its made when i type Humanoid:LoadAnimation and that i’ve already did that

Can you point where line 89 is on your code?

basically is the loadanimation things

idleAnim = hum:LoadAnimation(script:WaitForChild("Hold"))
	shootAnim = hum:LoadAnimation(script:WaitForChild("Recoil"))
	reloadAnim = hum:LoadAnimation(script:WaitForChild("Reload"))
	emptyanim = hum:LoadAnimation(script:WaitForChild("empty"))

When a character is loaded, not everything is loaded at the same time, and it takes time for some parts of the character to load, like the Humanoid. What I think is going on here is that the game tries to animate a humanoid that doesn’t exist yet and thus might be the reason you are getting the error. Add checks to the code to see if the Humanoid object exists before applying the animations.

Try changing

local char = plr.Character or plr.CharacterAdded:Wait()

to

repeat wait() until plr and plr:HasAppearanceLoaded()
local char = plr.Character
2 Likes

thank you and the other people that helped me! have a good day