Stopping an Animations Auto-Replication

Ive made a damage animation for when a player gets hit.

Currently whenever you hit a player it will play this animation on your client, then it will play the same animation on everyone else’s clients.

The only problem with this is when it plays the animation for yourself on your client it will auto-replicate to everyone else making it play the animation a second time on the server.

Is there any way to stop the animation from auto-replicating when your client plays the animation on your character?

1 Like

Uh, I guess the best way is to detect on the server when an unnamed animation (if played on the client the name isn’t replicated so it’s named “Animation”) is played through Humanoid.AnimationPlayed, and then stop it or maybe destroy it? To be honest I don’t even know if it would work since it might stop on the client too.

1 Like

I could try and detect whenever an animation is played on anyones animator then stop it if its the same ID as the damage animations.

EDIT: though this would have to be done on everyones clients since stopping it on the server would stop it on your client so i would have to whitelist/mark all the damage animations that your client plays for other characters.

1 Like

That was actually an excellent idea.

What i did was i simply just detected every time a animation plays on any character within your client then if the track.Animation.AnimationId is the same of any on a blacklist table of IDs it stops it.

The animation only being named “Animation” also helps alot with detecting whether it was replicated or not.

3 Likes

Hello, I’ve stumbled across this post since I had the same problem, I’ve written this script in attempts to re-create your solution:

	for _, players: Player in pairs(PlayerService:GetPlayers()) do
		if players.Name ~= SpecificPlayer.Name then
			local pCharacters: Model = players.Character
			local pHumanoid: Humanoid = pCharacters:WaitForChild('Humanoid')
			local pAnimator: Animator = pHumanoid:WaitForChild('Animator')

			pAnimator.AnimationPlayed:Connect(function(animationTrack: AnimationTrack) 

				if animationTrack.Animation.AnimationId == ID then
					animationTrack:Stop(0)
				end				
			end)

		end
	end

These are the results:

Is there something I’m missing?

2 Likes

How are you still playing the animation for the other clients?

I’m trying to implement your solution and the script does pick up the animation and tries to cancel it, but it just doesn’t work and the animation awkwardly plays twice.

local plr = playerService:GetPlayerFromCharacter(char)
	remotesFolder.PlayAnimation:FireClient(plr, animName, toPlay)
	for i, otherPlr in pairs(playerService:GetPlayers()) do
		if otherPlr ~= plr then
			local otherChar = otherPlr.Character
			if otherChar then
				otherChar.Events.Remote.ReplicateAnim:FireClient(otherPlr, char, char.Weapon.Anims[animName], toPlay)
				local animator = char.Humanoid.Animator
				local event
				
				event = animator.AnimationPlayed:Connect(function(animTrack)
					print(1, animTrack.Animation.AnimationId, animInstance.AnimationId)
					if animTrack.Animation.AnimationId == animInstance.AnimationId then
						print("Quick Cancel")
						animTrack:Stop(0)
						event:Disconnect()
					end
				end)
				
				delay(10, function()
					if event then
						event:Disconnect()
					end
				end)
				
			end
		end
	end

I’m playing it via ClientEvent, I just have a function that’s ran client-sided that plays an animation.

for _, players: Player in pairs(PlayerService:GetPlayers()) do
		if players.Name ~= SpecificPlayer.Name then
			local pCharacters: Model = players.Character
			local pHumanoid: Humanoid = pCharacters:WaitForChild('Humanoid')
			local pAnimator: Animator = pHumanoid:WaitForChild('Animator')

			pAnimator.AnimationPlayed:Connect(function(animationTrack: AnimationTrack) 

				if animationTrack.Animation.AnimationId == ID then
					animationTrack:Stop(0)
				end				
			end)

		end
	end

This is inside that same client script, sorry for the confusion.

I implemented something similar a while back, and the weirdest thing is that it doesn’t work the first time an animation is loaded in (the animation plays twice), but works perfectly after that.


			if not anim then
				loadedAnims[charToAnimate][animInstance.Name] = animator:LoadAnimation(animInstance)
				anim = loadedAnims[charToAnimate][animInstance.Name]
				anim:Play()
			else
				anim:Play()
			end
			local event
			event = animator.AnimationPlayed:Connect(function(animTrack)
				print(1, animTrack.Animation.AnimationId, anim.Animation.AnimationId)
				if animTrack.Name == "Animation" and animTrack.Animation.AnimationId == anim.Animation.AnimationId then
					
					
					animTrack:Stop(0)
				end
			end)

			wait(anim.Length)
			if event then
				event:Disconnect()
			end

The event doesn’t fire when it’s first created, but works after that.