Humanoid:LoadAnimation() Help

So I’m trying to animate an eel, by playing a swimming animation when its moving. But it seems that humanoid:LoadAnimation() doesn’t actually work anymore or maybe I’m doing it wrong. Here’s the code I am running

while wait() do
	local Swim = script.Parent.Animations.Swim
	local PlayerNear = false
	local PlayerHRP
	local players = game.Players:GetPlayers()
	for i, v in pairs(players) do
		local Character = game.Workspace:WaitForChild(v.Name)
		if (Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < 5 then
			print("Near")
			PlayerNear = true
			PlayerHRP = v.Character.HumanoidRootPart
		end
	end
	
	if PlayerNear == true then
		script.Parent.HumanoidRootPart.BodyPosition.Position = PlayerHRP.Position
		script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, PlayerHRP.Position)
		local SwimAnimation = script.Parent.Humanoid:LoadAnimation(Swim)
	end
end

In the script it underlines script.Parent.Humanoid:LoadAnimation. So what I’m guessing is that it does not work anymore, but I don’t know what else to do since I can’t find anything about it anywhere. Does anybody know why this is happening? And what should I do instead to fix this.

1 Like

Humanoid:LoadAnimation does work, just that it’s not recommend to do so cause it’s “deprecated” at this point from now on

You should use the Animator object instead for loading animations, also you didn’t even Play the animation oof

while wait() do
	local Swim = script.Parent.Animations.Swim
	local PlayerNear = false
	local PlayerHRP
	local players = game.Players:GetPlayers()
	for i, v in pairs(players) do
		local Character = game.Workspace:WaitForChild(v.Name)
		if (Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < 5 then
			print("Near")
			PlayerNear = true
			PlayerHRP = v.Character.HumanoidRootPart
		end
	end
	
	if PlayerNear == true then
		script.Parent.HumanoidRootPart.BodyPosition.Position = PlayerHRP.Position
		script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, PlayerHRP.Position)
		local SwimAnimation = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Swim)
        SwimAnimation:Play()
	end
end
1 Like

Thanks, that works. Also, yeah I know I didn’t play the animation lol. I didn’t think it would work since the LoadAnimation was underlined.