[Resource] RollbackService - The "Time Machine" for Server Authority & State Validation

:waving_hand: 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

:glowing_star: What Can It Do?

RollbackService isn’t just for guns! It enables precise validation for:

  • :door: Interactions: Verify if a player was actually close enough to press a button or open a door at the moment they clicked.
  • :sparkles: Abilities: Check line-of-sight or positioning for spells cast in the past (relative to ping).
  • :shield: Anti-Cheat: Analyze player movement history to detect speed hacks or teleportation.
  • :crossed_swords: Combat: (Of course!) Standard lag-compensated hit registration.

:sparkles: Technical Features

  • :high_voltage: Buffer-Based: Built on Luau’s buffer library for maximum memory efficiency.
  • :brain: Zero-Allocation: Uses a pre-allocated RingBuffer so it never creates new tables during recording. Your GC will thank you! :wink:
  • :counterclockwise_arrows_button: Accurate Interpolation: Uses Slerp (Spherical Linear Interpolation) for rotations, ensuring smooth and accurate history reconstruction.
  • :puzzle_piece: Modular Schema: You define exactly what to record (Position, Velocity, Rotation, HumanoidState) to save bandwidth.

:wrench: How It Works

  1. Record: Every frame, the server captures a snapshot of the world state.
  2. Store: Data is packed into a circular binary buffer (RingBuffer).
  3. Rewind: When a client sends a request (like “I interacted with Object X”), you pass their timestamp to RollbackService.
  4. Verify: The service returns the exact state of the player at that moment in time, allowing you to validate the action fairly. >:3

:rocket: 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

:gear: 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!

:package: License

Open Source (MIT). Free to use in any project!
Get it! (12.2 KB)

[spoiler]For my Pinewood scientist application.[/spoiler]
16 Likes

I can see this pretty useful. Could you cover deeper how it works?

sure thing!

this module stores historical snapshots of player character states for later validation of time-sensitive actions. It consists of 5 components: Schema, RingBuffer, Recorder, Sampler and Interpolator.

  • Schema calculates the binary memory layout for snapshots based on configurable options.
  • RingBuffer manages circular storage with pre-allocated buffers and performs binary searches across non-contiguous data.
  • Recorder captures everything (position, rotation, velocity, humanoid states) into these buffers every heartbeat.
  • Sampler queries historical states by temporally interpolating between stored snapshots.
  • The Interpolator performs a bunch of math operations, most notably the quaternion spherical linear interpolation (Slerp) for reliable rotation transitions; it uses basic linear interpolation for position/velocity data.

when processing client claims, the system can “roll back” the game world to the action’s timestamp, reconstruct the authoritative positions using the sampled data, and validate whatever you need to validate.

it is quite fast too - thanks to native code gen (it is quite beneficial here due to the amount of math operations and actions with buffers), DoD approach (upvalue caching, avoiding expensive calls, etc.), and obviously the fact that we’re doing zero allocation here, to avoid pressure on the garbage collector.

you can achieve very serious security if you pair such a system with Roblox’s native Server Authority. Exploiters not only won’t be able to modify their character anymore, but they also wont be able to mess with other players by, for example, modifying their hitbox to be bigger or killing them from behind walls, because now the server also remembers who, where, how, and why.

2 Likes

Btw, it would be better if you could write a API document since it would make using it easier

So this would be really good for making new anti-exploit systems or building a new exploit system off of this. Nice resource! :grin: