Problem with LoadAnimation

Attempt to index nil with “LoadAnimation”

It works just fine when i move the loadanimation part OUTSIDE of the loop, i am not sure why…

local event = game.ReplicatedStorage:WaitForChild("ClientReplicator")

local groups = {}

local animations = game.ReplicatedStorage:WaitForChild("Animations")
local anims2 = game.ReplicatedStorage:WaitForChild("anims2")

event.OnClientEvent:Connect(function(group,state)
	if not groups[table.find(groups,group)] then
		table.insert(groups,group)
		print(group)
		for _,char in pairs(group) do
			
			print(char)
			print(char.Humanoid)
			local atease = char.Humanoid:LoadAnimation(animations.Idle)
			local aim = char.Humanoid:LoadAnimation(animations.Aim)
			local reload = char.Humanoid:LoadAnimation(animations.Reload)

			local idle = char.Humanoid:LoadAnimation(anims2.Idle)
			local walk = char.Humanoid:LoadAnimation(anims2.WalkAnim)
			local run = char.Humanoid:LoadAnimation(anims2.RunAnim)
			local jump = char.Humanoid:LoadAnimation(anims2.JumpAnim)
			
			local CharGroup = {
				char,
				atease,
				aim,
				reload,
				idle,
				walk,
				run,
				jump
			}

			table.insert(group,CharGroup)

		end
		print(groups)
	else
	
	end
end)

try making a local for the humanoid before you start the loop, also you should consider using Humanoid.Animator:LoadAnimation() instead as Humanoid:LoadAnimation() is deprecated

Problem persists. What i’m trying to do is load a bunch of animations on hundreds of chars then store them in a group table where i can individually play each one

does this print? if it does print the parent of it

humanoid could not exist plus humanoid:LoadAnimation does not work anymore

use humanoid.Animator:LoadAnimation

1 Like

it does still work but it’s deprecated

Not quite, it’s more of deprecated, which means it still works but it is no longer being fixed or updated.

im printing it right before. it exists

How did you have the code when you were loading the animation outside of the loop?

image

The first time you define the characters humanoid, you should use char:WaitForChild("Humanoid", 5)

This is largely due to the fact that your loop is likely moving too quick, adding that wait will wait until it can tell that the humanoid exists, making sure it isn’t nil

Again that wasn’t the problem, i fixed it though, turns out the chars were tables and not instances.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.