Animation not playing, and theres no errors

After you kill the animal NPC I have, a proximity prompt will be available that says, “Harvest” you can hold E and it SHOULD be playing a harvesting animation, but it wont for some reason. Also everything else is running, I am pretty sure its “Playing” the animiation because everything else after the Anim:Play() happens, everything else runs fine.
(There are no errors in the output and I’m very lost)

local ProximityPromptService = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")


local proximityPrompt = workspace.NPCS.Squirrel["Right Leg"].ProximityPrompt

local Animation = script.Animation
function getHumanoid(plr)
	local char = plr.Character 
	if not char then return nil end
	return char:FindFirstChildWhichIsA("Humanoid")
end

proximityPrompt.Triggered:Connect(function(player)
	local controls = require(player.PlayerScripts.PlayerModule):GetControls()
	local humanoid = getHumanoid(player) 
	if not humanoid then return end 

	local Anim = humanoid:LoadAnimation(Animation)
	humanoid:UnequipTools()
	proximityPrompt.Enabled = false
	controls:Disable()
	Anim:Play()
	task.wait(5)
	game.Lighting.Tools["Squirell Meat"]:Clone().Parent = player.Backpack
	proximityPrompt.Parent.Parent:Destroy()
	controls:Enable()
	Anim:Stop()
end)
local proximityPrompt = workspace.NPCS.Squirrel["Right Leg"].ProximityPrompt

local Animation = script.Animation
function getHumanoid(plr)
	local char = plr.Character 
	if not char then return nil end
	return char:FindFirstChildWhichIsA("Humanoid")
end

proximityPrompt.Triggered:Connect(function(player)
	local controls = require(player.PlayerScripts.PlayerModule):GetControls()
	local humanoid = getHumanoid(player) 
	if not humanoid then return end 

	local Anim = humanoid:LoadAnimation(Animation)
    while Anim.Length <= 0 do print("loading animation!") task.wait() end
	humanoid:UnequipTools()
	proximityPrompt.Enabled = false
	controls:Disable()
	Anim:Play()
	task.wait(5)
	game.Lighting.Tools["Squirell Meat"]:Clone().Parent = player.Backpack
	proximityPrompt.Parent.Parent:Destroy()
	controls:Enable()
	Anim:Stop()
end)

Try this

it printed, "loading animation! (x6)
And no animation played :frowning:

If it consistently prints that, then they’re chance ur animation isn’t loading correctly, make sure you own the animation and if its a group game then make sure the group owns the animation

Its owned by me, im not sure what to do.

Does the print go on forever? or does it only print a few times

it printed 6 times.

(character limit)

Okay that means it loaded then, can u check the priority of the animation make sure its on action or higher

2 Likes

Probably not relevant, but you could load it onto animator like you are meant to do (humanoid is deprecated for loading anims)

get rid of your findHumanoid function and add this instead

local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local Anim = animator:LoadAnimation(Animation)

And I’m not so sure you need to wait until the length is >0 but try waiting 0.5 sec to debug

1 Like

Like what @TheZanderius said, using humanoid to load animations is not recommended and instead use the animator inside a humanoid to load animations.

You checked to make sure you’ve put the animationID correctly?

1 Like

yes, I redid the ID around 3 times

What if you do a wait() before Anim:Play()?

It printed,

  10:31:13.794  loading animation! (x37)  -  Client - NPCharvest:19

Its like the code just skips the Anim:Play() line because everything else works.

Hm… how does your script look like right now?

1 Like

(this is located in StarterPlayerScripts)

local proximityPrompt = workspace.NPCS.Squirrel["Right Leg"].ProximityPrompt

local Animation = script.Animation
function getHumanoid(plr)
	local char = plr.Character 
	if not char then return nil end
	return char:FindFirstChildWhichIsA("Humanoid")
end

proximityPrompt.Triggered:Connect(function(player)
	local controls = require(player.PlayerScripts.PlayerModule):GetControls()
	local char = player.Character
	local humanoid = char:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")
	local Anim = animator:LoadAnimation(Animation)
	
	if not humanoid then return end 

	while Anim.Length <= 0 do print("loading animation!") task.wait() end
	humanoid:UnequipTools()
	proximityPrompt.Enabled = false
	controls:Disable()
	wait()
	Anim:Play()
	task.wait(5)
	game.Lighting.Tools["Squirell Meat"]:Clone().Parent = player.Backpack
	controls:Enable()
	Anim:Stop()
	proximityPrompt.Parent.Parent:Destroy()
end)
1 Like

This shouldn’t be a problem then. It might be how the animation is loaded. You made the priority of the animation to “Action”, right?

1 Like

That’s one thing I struggle with (since I’m new to animating) is the priority’s, I set it to action 3 I believe?

I’m not sure if that would actually work, I’m usually using Action. But other than that, it should work anyway.

Yeah im not really sure whats happening to be honest, should I record it all?

Yeah, and also record the output too if that could help identifying what’s wrong.