Animation Keyframe Events Not Functioning Correctly on the Server Side Due to Animation Latency

hey guys

I hope I’m posting in the right category! it was between this or game development but I figured it’s more of a scripting issue.

I’m in the midsts of developing a theme park game that I’ve been working on for two years. To explain the system I have a question on, I have an automatic character that walks around for four minutes. This character stays backstage until the animation is activated, then moves towards a gate to go onstage. I set two keyframe events, to open and close the gate.

Here’s one of the keyframe events

dance.KeyframeReached:connect(function(keyframeName)
	if string.match(keyframeName, "KeyframeOPENGATE") then
		print("reached keyframe, KeyframeOPENGATE initiating...")
		--gate1open--
		local tweenService = game:GetService("TweenService")
		local Properties = {
			CFrame =   game.Workspace.Gates4.Gate1OpenedPos.CFrame}
		local TweenInfoo = TweenInfo.new(4,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
		local tween = tweenService:Create(Gate1,TweenInfoo,Properties)
		tween:Play()
		local tweenService = game:GetService("TweenService")
		local Properties = {
			CFrame =   game.Workspace.Gates4.Gate2OpenedPos.CFrame}
		local TweenInfoo = TweenInfo.new(4,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
		local tween = tweenService:Create(Gate2,TweenInfoo,Properties)
		tween:Play()
		--gate1open--
	end
end)

Due to latency with the animation, for some players the gate will open before the animation is where it needs to be and closes before the character walks out. Thus, making it look like the character is running through the gate. As of right now everything is server side, the script is running on a classic script, not local or remote.

I’m curious if there is any way to fix this? I’d be fine if an animation looked glitchy but performed at the same time for every player rather than create disillusions. Any help is greatly appreciated!

You should be able to track the same animation events on the client, even if the animation was played from the server. As far as I know, the only way to find the animation track would be to search through all the playing animations on the animator. It’s annoying, but it would probably work. Replicated animations don’t retain names, so you should check for the matching AnimationId.