Basic GetAnimationTrack function causes "Player appears to be spamming remote events" and extreme ping only on client and not on studio

Context

My own game started having extreme ping and crash issues at the beginning of the week within client. Due to the game not being public, I only noticed this bug monday but it could have been an issue for longer. This bug was tedious to diagnose and basically make my game completly unplayable online.

When using a simple GetAnimationTrack function on the client side for the local player’s character on a large amount of animation over a whole game. The function seems to start generating high amount of ping and the “Player appears to be spamming remote events” message starts appearing in the server’s console. At the same time, this problem only occurs on the live client and not within studio.

Here the common “GetAnimationTrack” function used.

function GetAnimationTrack(Animation: Animation)
	local Char = game.Players.LocalPlayer.Character
	if not Char then return end 
	
	local Hum = Char:FindFirstChild("Humanoid")
	if not Hum then return end
	
	local Animator = Hum:FindFirstChild("Animator") :: Animator
	if not Animator then return end
	
	for _,v in Animator:GetPlayingAnimationTracks() do
		if v.Animation.AnimationId == Animation.AnimationId then
			return v
		end
	end
	
	return Animator:LoadAnimation(Animation)
end
Video of repro

Imgur: The magic of the Internet

Place showing off the issue: Animation related bug causing high ping - Roblox
Place’s file: Animation Related Bug Causing High Ping.rbxl (83.8 KB)

The textbox allows input the amount of calls to random animation of this function to be performed per frame.
For the need of this repro file, I’ve scrapped a lot of UGC animation to simulate a game with high amount of different animation.

Expected behavior

I’ve used this function for literal years and I never had this issue until now. It shouldn’t produce the “Player appears to be spamming remote events” within the live game.

If it ends up being a bad practice, could we atleast have a similar issue happen in studio too?

bump also im getting 100+ ping for using this once

Hi! I tried on the experience you provided (saved to Roblox and joined from client), and my ping stayed very reasonable (~60ms) even when calling GetAnimationTrack() 100 times per frame. Can you confirm this is still happening for you?

Thanks!

Hi, thank you for taking the time to investigate this issue.

I have updated the place file. Some of the animations that were present at the time of the original report have since been removed.
Updated place file: Animation Related Bug Causing High Ping Updated.rbxl (87.0 KB)

From my recent testing, the issue no longer occurs while the character is idle.

However, I was able to reproduce the problem by repeatedly spamming random inputs such as jumping and movement. When doing this, the ping increases significantly. Once the input stops, the ping slowly returns to normal.

At the time of the original report, the ping would remain high after the issue was triggered. It now appears that some engine update may have changed this behavior.

I have attached a new video demonstrating the reproduction steps.

Thank you again for your help.

EDIT: I’ve noticed the place I’ve published got privated, I’ve re-opened it + uncopylocked it.