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.