Server does not stop playing animation

I have a replication system in my game where every client plays every animation and effect for themselves (I know it’s redundant for animations but it did not cause issues earlier) and an animation doesn’t seem to stop on the server side for a reason I don’t quite understand.
I have a looped barrage animation and first I tried just using :Stop on it and it works perfectly, but the animation ends abruptly and I wanted to make it smoother, so I tried setting .Looped to false to stop it but it did not work (doesn’t stop on server) so I added a delayed :Stop and it still does not work. I am out of ideas and I can’t seem to find a similiar post with a solution that works on the dev forum.

Here’s the code and result for my first solution (note I’m using the for loop because just calling :Stop() on the AnimationTrack object caused the server to not replicate animation stopping as well in previous attacks):

for index, animation in ipairs(animator:GetPlayingAnimationTracks()) do
	if animation.Animation.Name == "PunchFlurry" then
		animation.Looped = false
		animation:Stop()
	end
end

Result: https://streamable.com/dg6xa7

Second version:

for index, animation in ipairs(animator:GetPlayingAnimationTracks()) do
	if animation.Animation.Name == "PunchFlurry" then
		animation.Looped = false
        -- math.max in case for whatever reason animation.Length returns 0.
		task.delay(math.max(animation.Length - animation.TimePosition, 0.01), function()
			animation:Stop()
		end)
	end
end

Result: https://streamable.com/2fn2rn

I’m guessing taht the client thinks the animation is over, so :Stop() doesn’t do anything and the server for whatever reason doesn’t stop the animation once the client does (I think it might have to do with me setting .Looped to false). Is there any way to stop server from replicatiing animations to other clients?

1 Like

To stop the animation on the server and synchronize it with the clients, you can use either remote events or remote functions for synchronization, or utilize a custom property. Both approaches will help achieve consistent animation stopping across all clients.

Making an additional remote just to stop the animation which shouldn’t be playing on the server in the first place is very extra and just a walkaround for the issue, is there a way to stop it from happening at all?

If you’re having this issue then this:

is true. AnimationTrack.Looped does not replicate and you need to do a workaround. If you want to keep things on the client then this is what worked for me:

for index, animation in ipairs(animator:GetPlayingAnimationTracks()) do
	if animation.Animation.Name == "PunchFlurry" then
		task.delay(math.max(animation.Length - animation.TimePosition, 0.01), function()
			animation:AdjustWeight(0.0001, 0.2)
			task.wait(0.2)
			animation:Stop()
		end)
	end
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.