Animation Not Working

Hey everyone! I am working on a game, and my animation is not working. I am doing this animation on the server because I want everyone to see the player doing the animation. I am not sure if that is right. :person_shrugging: I do not want the player to move during the animation, so I am anchoring their HumanoidRootPart. Maybe that is the reason, not sure. As you can tell, I am not that experienced with animations. Anyways, here is my script:

    local humanoid = player.Character:WaitForChild("Humanoid")
	local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart.CFrame = game.Workspace:WaitForChild("MakeTable").CFrame
		humanoidRootPart.Anchored = true
		local anim = RS:WaitForChild("BrewAnimation")
		
		local animator = humanoid:WaitForChild("Animator")
		
		local trackAnim = animator:LoadAnimation(anim)
		
		trackAnim:Play()
		
		task.wait(5)
		
		trackAnim:Stop()

		humanoidRootPart.Anchored = false
		

If you know what I can change to make this animation work, please let me know! Thank you all!!! :heart:

Did you try loading the anim to the Humanoid instead of the Animator? It is deprecated, but it still may work.

Also a few things unrelated to your problem;

  1. You do not need to do trackAnim:Stop() if your animation is not looped. It will stop automatically once the animation is finished.
  2. It is better to use workspace or game:GetService("Workspace") rather than using game.Workspace which isn’t recommended.
1 Like

For loading it to the humanoid do you mean

local trackAnim = humanoid:LoadAnimation(anim)

that’s deprecated, don’t do it like that
what you did originally was right to load the animation, use Humanoid.Animator:LoadAnimation() to load the animation

That did not work. Also, I forgot to mention my animation is set to Action 4 and is looped.

i’m guessing you own this animation, and it isn’t uploaded by a group or anything?

Yup I just made it in studio a little bit ago.

1 Like

are you sure its actually getting past the RS:WaitForChild line

could it be possible that you forgot to close the if humanoidRootPart statement, considering I don’t see it closed in the lua script block?

1 Like

it would’ve errored pretty obviously if that was the case

1 Like

Here is the full part of that script:

craftPotionEvent.OnServerEvent:Connect(function(player, potionName, potionColor)
	local humanoid = player.Character:WaitForChild("Humanoid")
	local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart.CFrame = workspace:WaitForChild("MakeTable").CFrame
		humanoidRootPart.Anchored = true
		local anim = RS:WaitForChild("BrewAnimation")
		
		local animator = humanoid:WaitForChild("Animator")
		
		local trackAnim = humanoid.Animator:LoadAnimation(anim)
		
		trackAnim:Play()
		
		task.wait(5)
		
		trackAnim:Stop()

		humanoidRootPart.Anchored = false
		
		local backpack = player:WaitForChild("Backpack")

		local potionToClone = finalPotionModels:FindFirstChild(potionName):Clone()
		potionToClone.Beaker.Color.Color = potionColor
		potionToClone.Parent  = backpack

	end
end)

Did you try to debug? Try to add a print under if humanoidRootPart then and see if it prints.

3 Likes

try adding print statements after the ifs and WaitForChilds

2 Likes

Ok, so I am not the best at debugging, but I added these prints:

craftPotionEvent.OnServerEvent:Connect(function(player, potionName, potionColor)
	local humanoid = player.Character:WaitForChild("Humanoid")
	local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		print("HumanoidRootPart found")
		humanoidRootPart.CFrame = workspace:WaitForChild("MakeTable").CFrame
		humanoidRootPart.Anchored = true
		local anim = RS:WaitForChild("BrewAnimation")
		
		if anim then
			print("Animation found")
		end
		
		local animator = humanoid:WaitForChild("Animator")
		
		if animator then
			print("Animator found")
		end
		
		local trackAnim = humanoid.Animator:LoadAnimation(anim)
		
		trackAnim:Play()
		
		print("anim playing")
		
		task.wait(5)
		
		trackAnim:Stop()

		humanoidRootPart.Anchored = false
		
		local backpack = player:WaitForChild("Backpack")

		local potionToClone = finalPotionModels:FindFirstChild(potionName):Clone()
		potionToClone.Beaker.Color.Color = potionColor
		potionToClone.Parent  = backpack

	end
end)

After this I tested it and this is what the output looked like:

10:51:06.969 HumanoidRootPart found - Server - IngredientsGiver:31
10:51:06.970 Animation found - Server - IngredientsGiver:37
10:51:06.971 Animator found - Server - IngredientsGiver:43
10:51:06.971 anim playing - Server - IngredientsGiver:50

And nothing played.

1 Like

could you show a video of the code running?

2 Likes

What Scooter said. Also,

^ Did you put the correct anim ID in BrewAnimation? Could you maybe show us what the properties (for the anim) look like?

2 Likes


Here is the video.

I made sure to double check that and I even thought it was the animation that was uploaded wrong so I went and made a new one.

Is your avatar matching the R version?

Is there a specific reason you’re doing it in the client? If not, you should do it on the server.

^ You shouldn’t be doing these on the client.