Animation not playing

Why isn’t my animation playing? I’ve changed the priority and even do ‘hum.Animation:LoadAnimation()’. Any answers would be greatly appreciated, thanks!

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild('Humanoid')
local mouse = plr:GetMouse()
local animTrack = hum.Animator:LoadAnimation(script.Animation)
animTrack.Priority = Enum.AnimationPriority.Action
print(animTrack.Priority)
local curr = 1

mouse.Button1Down:Connect(function()
	animTrack:Play()
	print('anim played')
end)

Have you checked if maybe the animation ID is empty or the animation itself

and Id use hum:LoadAnimation(anim) instead of hum.Animator:LoadAnimation(anim) because referencing animator directly is said to be deprecated as shown here Deprecating LoadAnimation on Humanoid and AnimationController

lastly, you know your code best, I can only do so much to attempt to help you in this case.

Hey! I changed hum.Animator:LoadAnimation() to hum:LoadAnimation() and checked if the animation ID is empty(it isn’t), and yet it still doesn’t work. Hopefully I quick skim of my code gives you an idea.

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild('Humanoid')
local mouse = plr:GetMouse()
local animTrack = hum:LoadAnimation(script.Animation)
animTrack.Priority = Enum.AnimationPriority.Action
print(animTrack.Priority)

mouse.Button1Down:Connect(function()
	animTrack:Play()
	print('anim played')
end)

hum:LoadAnimation is deprecated. You were right before you want to use Animator:LoadAnimation

try doing:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild('Humanoid')
local mouse = plr:GetMouse()
local animTrack = hum:LoadAnimation(script.:WaitForChild("Animation")
animTrack.Priority = Enum.AnimationPriority.Action
print(animTrack.Priority)

mouse.Button1Down:Connect(function()
	animTrack:Play()
	print('anim played')
end)

using WaitForChild on getting animation instance

if it doesnt work reply to this and i’ll try my best to help!

Hi! I changed the mouse to be a tool and also implemented the changes that you recommended and it still doesn’t work.

My current code:

local tool = script.Parent

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild('Humanoid')

print('here')

local anim = humanoid:LoadAnimation(tool.Anims:WaitForChild("Animation"))
anim.Priority = Enum.AnimationPriority.Action

print('yes sir')
	
tool.Activated:Connect(function()
	anim:Play()
	print('Animation')
end)

image

So this is an issue of either the id itself, if the game is a group game, then the animation must be uploaded to the group. If someone else owns the game, then it must be uploaded under their profile. If you own the game, you need to keep it under your ownership.

And,

local char = plr.CharacterAdded:Wait()

to

local char = plr.Character or plr.CharacterAdded:Wait()

Since animation code variates ill give you a piece of my code that you can implement in yours as a reference or to define something (sample code) since i don’t have a lot of time at the moment.

local ShotgunAnimIdle = Instance.new("Animation")
ShotgunAnimIdle.AnimationId = "rbxassetid://10004688896"
local AnimationTrackShotgunIdle = Humanoid.Animator:LoadAnimation(ShotgunAnimIdle)
AnimationTrackShotgunIdle.Priority = 3
Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		-- when moving
	else
		-- other part of stuff here
	end
end) 

Alright just tested it, here’s what worked for me:

local tool = script.Parent

local plr = game.Players.LocalPlayer

repeat task.wait() until plr.Character

local char = plr.Character
local humanoid = char:WaitForChild('Humanoid')

local anim = humanoid.Animator:LoadAnimation(tool.Anims:WaitForChild("Animation"))
anim.Priority = Enum.AnimationPriority.Action

tool.Activated:Connect(function()
	anim:Play()
	print('Animation')
end)

you were still using the deprecated Humanoid:LoadAnimation other than Animator:LoadAnimation