NPC/Mob Animation delayed for client compared to server

Hitbox & Animation Desync Issue (Client vs. Server)

1. What do you want to achieve?

I want to make sure that my hitbox timing matches the animation on both the client and server, so that hit detection feels accurate.

2. What is the issue?

On the server, the hitbox and animation are perfectly synchronized. However, on the client, the animation appears to be delayed, making the hitbox seem out of place. This leads to visually inaccurate blocks and hit detection.

Here are some screenshots of the issue:

https://i.gyazo.com/2fc1660003e68c6fe2fcf1510e1eef0b.gif

3. What solutions have you tried so far?

  • I tried raycasting (blue X’s) and spatial queries (OverlapParams)(The blue parts), but both methods suffer from the same issue.
  • I attempted to delay the hitbox activation to match the client animation, but this didn’t solve the problem.
  • I searched the Roblox Developer Hub, but I haven’t found a working solution yet.

4. Additional Details

  • The hitbox is managed on the server.
  • The animation plays on the server.
  • The issue could be caused by network delay or animation replication issues.

Does anyone know how to ensure that the hitbox and animation stay in sync for both the client and server? Any help is appreciated!

This is currently in a server script in the NPC

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HitboxModule = require(ReplicatedStorage:WaitForChild("Modules").HitboxServer)

local Model = script.Parent
local Humanoid = Model:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Hitboxes = script.Parent:WaitForChild("Hitboxes")

local AnimationTrack = Instance.new("Animation")
AnimationTrack.AnimationId = "rbxassetid://92122899475741"
local anim = Animator:LoadAnimation(AnimationTrack)

local hitbox = HitboxModule.new(Hitboxes.LongHitbox,Model)

hitbox.OnHit:Connect(function(character, humanoid)
--	print("hit")
end)

anim:GetMarkerReachedSignal("hitboxend"):Connect(function()
	hitbox:End()
	Hitboxes.LongHitbox.Transparency = 1
end)

anim:GetMarkerReachedSignal("hitboxstart"):Connect(function()
	hitbox:Start()
	Hitboxes.LongHitbox.Transparency = 0.6
end)

anim:Play() 

If there is any more information you need let me know.

you can try get the client’s network delay and play the animation on clientside and cal when should the hitbox be detected

Playing on the client would cause more issues than solve, since the hitbox is on the server the client playing the animation means the server the sword isn’t moving and it could desync worse

https://i.gyazo.com/2fc1660003e68c6fe2fcf1510e1eef0b.gif

This gif a is a good visualisation of the issue I currently have

found an old reply

or even you can do the target hitbox on the clientside too and tell the server are you being hit, and serverside can just check if any hits are missing for more security

It was due to a model containing over 2000 moving parts (1 model) on the physics server, probably causing the noticeable server lag/delay

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