Loop animate NPC on humanoid

This topic is related to an inquiry about the use of animations here, but the topic question is not the same here!

https://devforum.roblox.com/t/moving-character-arms-to-a-specific-position/376985/8


Player1 arrested by Player2.

This is done by a RemoteEvent to an animation script in StarterCharacterScripts. It’s also having a detection between NPC’s and PC’s.
PC’s are working completely. :smiley:

NPC’s aren’t animating, sadly. This is my code:

local arrestAnimation = Instance.new("Animation")
arrestAnimation.AnimationId = "rbxassetid://4178326828"
--[
-- Arrestation script activator with some other code here. Not relevant to the topic.
--]
arrestAnimationTrack = Humanoid:LoadAnimation(arrestAnimation)
arrestAnimationTrack:Play()

It doesn’t run, not even on scriptless rigs. The animation is set on looping at the editor.

How would I animate NPC’s properly using the Humanoid?

i… don’t quite get it ? The title mention you want to stop it,
But what you’re telling us with your code is tthat the NPC is not even playing the animation ?
not even on “normal rigs”
and your final question is

so i’m utterly confused, but you can just do :Stop() as long you have the animation loaded as a variable, however, if you don’t, you can eventually check & access all animations on a Humanoid with the following :

local AnimationTracks = Hit.Parent.Humanoid:GetPlayingAnimationTracks()
	for i, track in pairs (AnimationTracks) do
		if track == "AnimationName" then
			track:Stop()
			break
		end
	end

I’d apologize for my writing which could lead into confusion. My code is indeed not working properly. I emphasized stopping an animation, which I shouldn’t have done.

To make it clear:
I want to let a NPC animate using the function Humanoid:LoadAnimation(). Roblox is only providing information about animating NPC’s using an AnimationController.

um, so i went ahead and checked your asset
https://www.roblox.com/library/4178326828/Arrest-R6

image
So, your animation is called R6 and the NPC is a R15 ? :thinking:

The example I’ve sent is a Player Character. My NPC’s are R6. NPC’s are just walking around like nothing happened.

You said you used a AnimationController, according to

You don’t load via Humanoid, but AnimationController

local humanoid = npcModel:FindFirstChildOfClass("Humanoid")
humanoid:Destroy()
local animationController = Instance.new("AnimationController", npcModel)
 
-- Create and load an animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507771019" -- Roblox dance emote
local animationTrack = animationController:LoadAnimation(animation)
 
-- Play the animation
animationTrack:Play()

If I wasn’t clear enough, it’s my mistake. What I meant was the following:

To be honest, I really need Humanoids. I can’t work without them. I need to move them and walk around using PathFinding.

Then, are you certain that the example included

example=Humanoid:LoadAnimation(script.Parent.AnAnimation)
example:Play()

doesn’t work ?
cause this is the simpliest that exist, the animation itself or the way you trigger the function might be the issue.

1 Like

I see that the code given in your post is an animation that you created (Instance.new(“Animation”)? Have you placed it or cloned it into the destination desired?

I haven’t given it a specific location. I’ll parent it to the character model and check if that’s solving the case.

I’ve tried replacing the code so it creates an ‘Animation’ in the character model everytime an arrest is invoked. The same result, no results…

How would you suggest me to call the animation function? Maybe I’m calling the function using a wrong way, could you provide an example?