Hello!
Get it! (12.2 KB)
I’m thrilled to share RollbackService, a highly optimized engine that gives your server a “memory” of the past. While often used for lag compensation in shooters, this service is designed to be a general-purpose source of truth for any time-sensitive mechanic. This pairs exceptionally well with Roblox’s up-and-coming native Server Authority.
If you’ve ever had players complain “I was close enough to that door!” or “I definitely grabbed that item!”, this module solves that by allowing the server to look back at exactly what the player saw on their screen. <3
What Can It Do?
RollbackService isn’t just for guns! It enables precise validation for:
Interactions: Verify if a player was actually close enough to press a button or open a door at the moment they clicked.
Abilities: Check line-of-sight or positioning for spells cast in the past (relative to ping).
Anti-Cheat: Analyze player movement history to detect speed hacks or teleportation.
Combat: (Of course!) Standard lag-compensated hit registration.
Technical Features
Buffer-Based: Built on Luau’s bufferlibrary for maximum memory efficiency.
Zero-Allocation: Uses a pre-allocated RingBufferso it never creates new tables during recording. Your GC will thank you!
Accurate Interpolation: Uses Slerp (Spherical Linear Interpolation) for rotations, ensuring smooth and accurate history reconstruction.
Modular Schema: You define exactly what to record (Position, Velocity, Rotation, HumanoidState) to save bandwidth.
How It Works
- Record: Every frame, the server captures a snapshot of the world state.
- Store: Data is packed into a circular binary buffer (RingBuffer).
- Rewind: When a client sends a request (like “I interacted with Object X”), you pass their timestamp to
RollbackService. - Verify: The service returns the exact state of the player at that moment in time, allowing you to validate the action fairly. >:3
Usage Example
Here is how you can use it to validate a generic interaction, like picking up an item!
1. Setup
local RollbackService = require(path.to.RollbackService)
-- Initialize it
local rollback = RollbackService.new({
HISTORY_SECONDS = 1.5, -- Store last 1.5 seconds
TICK_RATE = 60, -- 60 snapshots per second
CAPTURE_ROTATION = true, -- We need rotation for some checks
CAPTURE_VELOCITY = false, -- Save memory if we don't need velocity
CAPTURE_HUMANOID_STATE = true,
DEBUG = true -- Visualizes where the server thinks they were!
})
rollback:Start()
2. General Interaction Validation
Imagine a player trying to pick up an item. On their screen, they were right next to it, but on the server, they might be moving.
local MAX_INTERACT_DIST = 8
function ValidateInteraction(player, targetPart, clientTimestamp)
local guid = tostring(player.UserId)
-- 1. Ask: "Where was this player X seconds ago?"
local historicState = rollback:Sample(guid, clientTimestamp)
if not historicState then
return false -- Data too old or player didn't exist
end
-- 2. Check: Was the player physically close enough *back then*?
local playerPos = historicState.Position
local targetPos = targetPart.Position
local distance = (playerPos - targetPos).Magnitude
if distance <= MAX_INTERACT_DIST then
print("Interaction Validated! ✅")
return true
else
warn("Interaction Failed: Player was " .. distance .. " studs away. ❌")
-- The DEBUG option will draw a red box at 'playerPos' so you can see why!
return false
end
end
Configuration
You can tune the service to fit your game’s memory budget:
| Option | Type | Description |
|---|---|---|
HISTORY_SECONDS |
number | How far back into the past the server remembers. |
CAPTURE_ROTATION |
boolean | Turn off if you only need position checks (saves 16 bytes/frame). |
CAPTURE_HUMANOID_STATE |
boolean | useful for checking if a player was Jumping or Falling. |
CAPTURE_CUSTOM_STATE |
boolean | Can be extended to track custom bitmasks! |
License
Open Source (MIT). Free to use in any project!
Get it! (12.2 KB)