Why can't I add this table inside of this one?

I’m having some trouble here. This is my code:

local Anims = game.ReplicatedStorage.MainGame.Animations:WaitForChild(Tool.Name)

local LoadedAnims = {}

local function LoadAnims()
	for _, Anim in pairs(Anims:GetDescendants()) do
		if Anim:IsA('Animation') then
			ContentProvider:PreloadAsync({Anim})
			
			local success, errorMsg = pcall(function()
				if Anim.Parent == Anims then
					LoadedAnims[Anim.Name] = Hum:LoadAnimation(Anim)
				else
					LoadedAnims[Anim.Parent.Name][Anim.Name] = Hum:LoadAnimation(Anim)
				end
			end)
			
			if success then
				print(Anim.Name)
			else
				warn(errorMsg)
			end
		end
	end
end

This is where the script is located:

image

The animations:

image

I keep getting this error message:

"

Players.Dev_Transparent.Backpack.Fists.WeaponClient:33: attempt to index nil with ‘Anim1’

"

If anyone can help w/ this that would be greatly appreciated. Thanks!

2 Likes

What does Hum:LoadAnimation(Anim) returns?

1 Like
LoadedAnims[Anim.Parent.Name]

^ This is not a table yet, you need to initiate it as a table. Right now it’s nil so that’s why it’s telling you you’re trying to index with nil

3 Likes

Well, when it’s not inside a folder other then “Anims”, ex:

LoadedAnims[Anim.Name] = Hum:LoadAnimation(Anim)

It loads the animation fine, so I’m pretty sure it would just return a loaded animation right?

2 Likes

Nvm, found the solution:

if Anim.Parent == Anims then
	LoadedAnims[Anim.Name] = Hum:LoadAnimation(Anim)
else
	if LoadedAnims[Anim.Parent.Name] == nil then
		LoadedAnims[Anim.Parent.Name] = {}
	end
				
	LoadedAnims[Anim.Parent.Name][Anim.Name] = Hum:LoadAnimation(Anim)
end

Just creating a table if that key == nil.

1 Like

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