Why is this Animation script not working?

I’m trying to make this animation loop until I stop it but it won’t seem to play. I’ve checked with print statements that ive got the humanoid and I have the right one, animaton just doesnt seem to play so any help would be appreciated.

local Players = game:GetService("Players")

local tool = script.Parent
local animation = tool.EatingAnimation

tool.Activated:Connect(function()
	local player = Players:FindFirstChild(tool.Parent.Name)
	if script.Parent.Debounce.Value == false then 
		script.Parent.Debounce.Value = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		local anim = humanoid:LoadAnimation(animation)
		anim:Play()
		task.wait(3)
		anim:Stop()
		player.leaderstats.Desserts.Value += 1
		script.Parent.Debounce.Value = false
	end
end)

Everything works apart from visually seeing animation also I’m doing a commision and the animation has been published by the guy I’m working for because it’s his game so idk if that has anything to do with it.

1 Like

try using humanid.Animator:LoadAnimation(animation)

do I need to create a Instance which is a animator or does it already have one?

1 Like

If it’s a player’s character then, no you don’t need to create an “Animator” for that since the character’s humanoid automatically created it.

1 Like

still doesn’t work and 0 errors in the output

What script did you use? It is server sided ( the normal one ) or client sided ( LocalScript )?

lmao bro it’s server sided didnt need to put (normal one) :joy:

1 Like

Haha lol, I put that there since my brain might mistake it.

1 Like

aha fair enough do u reckon issue in script could have to do with me not owning it and it not being my game?

I think the problem here is that the animation get override by another animation that has the same priority as that animation

do you know anyways that I Could fix that?

Yeah I think it’s this one :

anim.AnimationPriority = Enum.AnimationPriority.Action -- Set the animation's priority to "Action"

I already set the priority to action when i made animation and I get this with that script

Change that to this, maybe it will work? :

anim.Priority = Enum.AnimationPriority.Action -- Set the animation's priority to "Action"

Don’t ask why

It doesnt error but still doesnt work

Maybe try to change the animation’s priority to the highest ( Action4 ).

No errors but still doesn’t play

heres script rn

local Players = game:GetService("Players")

local tool = script.Parent
local animation = tool.EatingAnimation

tool.Activated:Connect(function()
	local player = Players:FindFirstChild(tool.Parent.Name)
	if script.Parent.Debounce.Value == false then 
		script.Parent.Debounce.Value = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		local anim = humanoid.Animator:LoadAnimation(animation)
		anim.Priority = Enum.AnimationPriority.Action4
		anim:Play()
		task.wait(3)
		anim:Stop()
		player.leaderstats.Desserts.Value += 1
		script.Parent.Debounce.Value = false
	end
end)

try removing the “Animator” since I think that is only for client sided or something.

Yes, if you don’t own the animation. It won’t work, to make it work, you’re going to have to publish the animation in your game. Otherwise, there’s nothing that you can do to fix it.