Animations In-game Not Playing

I’ll start with that I know very little about animating other than what’s on the Roblox API reference so it’s likely I’ve missed something.

I have a few actions in the game I’m making which trigger animations. In my studio sessions when I’ve hit play these have worked perfectly, and played as desired. However, as soon as I enter an in-game session the animations cease to work.

I’ve already set their animation priority to Action and in all cases I’ve tried printing AnimationTrack.IsRunning, which has returned true. All animations I’m using run on the server.

Example of how I’m running the animations:

local function Action(player)
	local Animation = script:WaitForChild("Animation")
	local AnimationTrack = player.Character.Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
	print(AnimationTrack.IsPlaying) -- prints true
	player.Character.Tool.ParticlePart.ParticleEmitter.Enabled = true
	print(AnimationTrack.IsPlaying) -- prints true
	AnimationTrack.Stopped:Wait() -- script waits infinitely here
	print(AnimationTrack.IsPlaying) -- never prints
	player.Character.Tool.ParticlePart.ParticleEmitter.Enabled = false
end

RemoteFunction.OnServerInvoke = 
	function(player, mouseTarget)
		-- some code
		Action(player)
	end

As I said the script functions perfectly in my studio sessions, so it must be to do with a difference between how the two sessions (studio vs. in-game) are handled.

Humanoid:LoadAnimation() is deprecated, an alternative is using Animator, which is a child of the player’s humanoid instance, so Animator:LoadAnimation().

Are you sure the animation is created by you?

That’s good to know. I’ll change that now. I don’t think it should be the thing causing issues though.

Yes. I’m 100% certain.

There’s an announcement about Humanoid is deprecated for loading animations.

Could you explain the process of using Animator to start animations from the server?

Use a RemoteEvent to play the animation, they should be played locally.

Useful Link

I don’t think it makes any real difference, although I am confused as to the replication of animations when they play from the client. I’ll try playing it from the client, but I’m inclined to trust this response.

The Animator can be created like any other instance meaning server sided animation is possible, as suggested by: Deprecating LoadAnimation on Humanoid and AnimationController

So surely you could do something like this:

local Animator = Instance.new("Animator")
	Animator.Parent = player.Character:WaitForChild("Humanoid")
	local Animation = script:WaitForChild("Animation")
	local AnimationTrack = player.Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Animation)

Is the animation owned by you? If it isn’t then that’s why. You can only play your animations in game. (it works in studio). If it is not owned by you, just open the animation up in the animation editor, and export it as yours and replace the IDs

It’s owned by me and was created by me.

I’ve also now tried playing the animation locally, to no avail.

local Animation = script:WaitForChild("Animation")
local AnimationTrack = character.Humanoid:WaitForChild("Animator"):LoadAnimation(Animation)
AnimationTrack:Play()
AnimationTrack.Stopped:Wait()

The script gets caught at the AnimationTrack.Stopped event again.

For anyone who’s interested, the animations weren’t playing because the game I was editing was a group place which required group animations.

The fact that you can’t use your own animations, but have to publish them as group animations just to make them work is unbelievably stupid and nonsensical. This fact should also be made much more clear on the API reference.

On a side note if anyone could affirm that this is the correct way to produce animations on the server I would be very grateful.

local Animator = Instance.new("Animator")
Animator.Parent = player.Character:WaitForChild("Humanoid")
local Animation = script:WaitForChild("Animation")
local AnimationTrack = player.Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Animation)