Trouble creating an animation in an NPC

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

When my player kicks (or punches) another player or NPC I want an animation to play in that other player or NPC (animation causes them to slump over).

  1. What is the issue? Include screenshots / videos if possible!

It works great against other players in the game but not with any NPCs.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I am using the same code for both players and NPCs because they both have a Humanoid to apply the animation against. This did’t work so I added a line to make sure this slumping animation was the highest priority animation since often the NPC is engaged in an animation when I am kicking or punching them. This did not solve the problem

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is my code on the Server side

game.ReplicatedStorage.PunchEvent.OnServerEvent:Connect(function(player, victim, humanoid)
	
	local animation = Instance.new("Animation")
	animation.AnimationId = "https://www.roblox.com/Asset?ID="..8381045470	
	loadedAnimation = humanoid:LoadAnimation(animation)	
	loadedAnimation.Priority = Enum.AnimationPriority.Action	
	loadedAnimation:Play()
	
end)

Here is my code on the client side:

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)	
	
	if hit.Parent:FindFirstChild("Humanoid") then
		PunchEvent:FireServer(hit.Parent, hit.Parent.Humanoid)	
        end	

end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Does your NPC have a humanoid/animation controller and is it rigged?

thanks for the reply. I don’t know if it has a controller? Would that be a script called “controller?” If so, I don’t see any scripts by that name. Also I don’t know what you mean “is it rigged?”