NPC animation won't play

Hello fellow developers, I’m making an ability where you hit someone and they get knocked back and play an animation. However, the animation just doesn’t play. Heres my script:

enemyanim.Parent = v.Humanoid
EnemyHit = v.Humanoid.Animator:LoadAnimation(enemyanim)
EnemyHit:Play()

(“V” was found through magnitude" All the dummies parts are unanchored and everything but it just doesn’t play even when I tried it on another real player. Anyone know why?

Maybe set the priority to Action? (if you dont have it on that)

Unfortunately still doesn’t work ;/

is it possible you have an animation with a higher priority than action? try setting the animation priority of EnemyHit to Action4

what is the priority of the animation?

It was first set to movement, then action, then action4 but none of those worked for some reason

enemyanim.Parent = v.Humanoid
EnemyHit = v.Humanoid.Animator:LoadAnimation(enemyanim)

You should add local before setting variables.

enemyanim.Parent = v.Humanoid

You dont need to set an animation track to the humanoid as multiple scripts can play animations through the same animation instance ( I usually keep it in replicated storage )

Try setting the network ownership to nil. Maybe it cant play it because the plr has ownership?

is it possible if you could show us more of your code?

1 Like

A lot of it is probably irrelevant but here you go

	for _,v in pairs(workspace.Entities:GetChildren()) do
				if v ~= char and db == false then
					if v:FindFirstChild("HumanoidRootPart") then
						if (char.HumanoidRootPart.CFrame.p - v.HumanoidRootPart.CFrame.p).Magnitude <= 6 then
							if v.Humanoid.Health > 0 and active == true then
								enemyanim.Parent = v.Humanoid
							local EnemyHit = v.Humanoid.Animator:LoadAnimation(enemyanim)
								hit = true
								active = false
								Event_:Disconnect()
								if Idleanim1 then Idleanim1:Stop() end
								if Idleanim2 then Idleanim2:Stop() end
								local hitload = hum.Animator:LoadAnimation(hitanim)
								hitload:Play()

What do you mean network ownership? Where can i find that?

Is this in a server script because if it isn’t in one you have to set the npcs ownership to the character thats manipulating its animations.

It’s in a server script activated by a remote event sent by a local script

you can read about network ownership here but a quick bad summary is that if its ownership is nil the server handles its physics, animations, and other stuff but if its on a client then it handles it on that client, meaning the client can edit its position its animations and all that fun stuff.

Ownerships of unanchored parts are set to the nearest player and stuff

oh yeah, @ortacise makes a good point. If the server has ownership of the npc then it’s best to load and play the animation on the server

if (char.HumanoidRootPart.CFrame.p - v.HumanoidRootPart.CFrame.p).Magnitude <= 6 then

I think CFrame.p is deprecated you gotta use CFrame.Position

Maybe its not detecting the enemies in the first place?
try printing what enemies it finds in the range

I tried enemyanim:SetNetworkOwner(nil) but it said it wasn’t a valid member of enemyanim

No, its definitely detecting, later on I have code which damages the target and knocks them back so it’s for sure finding them

You cant set models ownerships they dont have ones, you have to set the BaseParts ones which I think you can just set its humanoidRootPart unless im wrong and you have to set all of them which u could do with a for i, v loop

The only thing I can think of thats causing it now is the animation track. Instead of setting the tracks parent to the humanoid try just loading it from replicatedStorage

code:
– server side –

local track = humanoid:WaitForChild("Animator"):LoadAnimation(replicatedStorage.Animations.Knocked)

remote.OnServerEvent:Connect(function(plr)
-- do ur stuff
if inrange then
track:Play()
end
end)

Doesn’t seem to be working, I did this.

for i,part in pairs(char:GetChildren()) do
										if part:IsA("BasePart") then
											part:SetNetworkOwner(nil)
											end
									end
								end)