Serverside animation player not working

I want to achieve a server-side animation player, however it keeps saying on line 31 that attempt to index nil with play.

Here’s the script:

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local AnimationsStorage = script:WaitForChild("Animations")
local CurrentPose 


local AllTracks = {}


for _,anim in pairs (AnimationsStorage:GetChildren()) do
	print("Loading Animations")
	AllTracks[anim.Name] = Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(anim)
	AllTracks[anim.Name].KeyframeReached:Connect(function(keyname)
		if Character.PrimaryPart:FindFirstChild(keyname) and Character.PrimaryPart:FindFirstChild(keyname):IsA("Sound") then
			Character.PrimaryPart:FindFirstChild(keyname):Play()
		end
	end)
end


--//Animation Setup

function RollAnimation(animname,priority,speed)
	print(animname)
	for i,v in pairs (AllTracks) do
		print(i,v)
	end
	print("Rolling Animation") 
	if AllTracks[CurrentPose] then
		AllTracks[CurrentPose]:Stop(Humanoid.WalkSpeed/100)
	end
	AllTracks[animname]:Play()
	AllTracks[animname]:AdjustSpeed(speed)
	CurrentPose = animname
end

--//Humanoid 

function OnRun(speed)
	if speed > 1 then --Walking
		RollAnimation("Walk",Enum.AnimationPriority.Core,(speed/Humanoid.WalkSpeed))
	else
		RollAnimation("IdleStanding",Enum.AnimationPriority.Idle,.3)	
	end
end

function OnIdled()
	RollAnimation("Idle",Enum.AnimationPriority.Idle,.3)
end

function OnJump()
	RollAnimation("Jump",Enum.AnimationPriority.Movement,.3)
end

function OnFall()
	RollAnimation("Fall",Enum.AnimationPriority.Movement,.3)
end

function OnDied()
	
end


OnIdled()

Humanoid.Running:Connect(OnRun)
Humanoid.Jumping:Connect(OnJump)
Humanoid.FreeFalling:Connect(OnFall)
Humanoid.Died:Connect(OnDied)

Please help :frowning:

It’s where it says AllTracks[animname]:Play()

1 Like

It’s possible your type is wrong on your table index

Try printing AllTracks. See what’s in there. Is animname a text or an instance? You might need animname.Name if it’s an instance.

Nil should only show up when you are trying to get a value that doesn’t exist. Does the value exist when you try to call it?

Exactly, there is no value in
image

AllTracks is populated after it is declared.

Look a bit more into the code. It shows where things get inserted in AllTracks.

1 Like

Instead of IdleStanding I put Idle and it worked! :slight_smile:
Thank you everyone!