I’m experiencing an issue where server-side hitboxes don’t always appear in front of players. Currently I’m using this ping compensation method:
local ping = math.clamp(player:GetNetworkPing(), 0, 0.3)
local pingOffset = 6.5 - 10 * ping
local velocityOffset = root.CFrame:VectorToObjectSpace(root.AssemblyLinearVelocity)
While this helps, it’s not perfect. The hitboxes still sometimes lag behind fast-moving players or don’t align properly. Are there better way to sync hitboxes more accurately?
Create the Hitbox on the client and validate the result on the server.
Example:
→ Client makes a hitbox. Exploiters can make it really big or in completely different position than normal, but it’s fine since we will check on the server. Client sends what was inside the hitbox to the server for the server to perform action.
→ Server receives things the client found in hitbox, and compares their position to the player’s position, verifying legitimacy with Magnitude checks. If is valid, server can perform action on what it found
This is what I use for hitboxes in my game and it ensures hitboxes feel responsive while also not giving leeway for exploits.
You could do something like this for a very basic velocity compensation on the server:
local ADJUSTMENT_CONSTANT = 2 -- Can be any number, higher = more aggressive
local hitboxCFrame = currentCFrame + (humanoidRootPart.CFrame.AssemblyLinearVelocity.Unit * ADJUSTMENT_CONSTANT)
-- do ur hitbox stuff here
Even if you get the hitbox to position correctly, the server may not register a hit for something that should very visibly be a hit for the client, leading to gameplay feeling annoying.
I understand the frustation of a rework like this, but it’s the best way to go about it imo.