Lag Compensation¶
Lag compensation for hitboxes is usually done with a table of player movement snapshots so you can rewind and view where a player was at. Chrono timestamps server snapshots using the server's os.clock while forwarding the client's clock for interpolation. This allows lag compensation to be done easily.
How?¶
Client¶
When firing a hitbox event, send workspace:GetServerTimeNow():
local clientServerTimeNow = workspace:GetServerTimeNow()
Hitbox:FireServer(targetPlayer, clientServerTimeNow)
Server¶
To use it for hit validation, receive the time, then rewind.
local Entity = require(chrono.Shared.Entity)
local Holder = require(chrono.Shared.Holder)
Hitbox.OnServerEvent:Connect(function(attacker: Player, target: Player, clientServerTimeNow: number)
local latency = workspace:GetServerTimeNow() - clientServerTimeNow
local rewindTo = os.clock() - latency
--you can also account for interpolation delay as well but you must send it from the client and then clamp it
--should also be validating the timestamps against something like Getnetworkping to prevent exploiters from spoofing it.
local attackerWasAt = Entity.GetAt(Holder.GetEntityFromPlayer(attacker), rewindTo)
local targetWasAt = Entity.GetAt(Holder.GetEntityFromPlayer(target), rewindTo)
end)