Roblox Checkpoint and Race Timing Systems: Building Lap Counters and Split Times That Can't Be Cheated

Can you prove that the lap time at the top of your leaderboard was actually driven? If you run a racing experience on Roblox, you should be able to.
Many track builders wire a Touched event to each checkpoint, fire a RemoteEvent from the client, and call it done. That said, a timing system that trusts the client can be rewritten by any exploit script, and the leaderboard ends up listing whoever edited a number first.
Where The Vehicle Guide Leaves Off
Our guide to Roblox vehicle physics and chassis tuning ends with a car that drives well. Next, that car needs a track that knows where the car is, which lap it is on, and how long each sector took.
Keep in mind that the timing layer runs entirely on the server and treats the car as a moving point. As a result, it works the same for a VehicleSeat kart, a custom constraint chassis, or a hovercraft built on AlignPosition.
A server-side race timer needs ordered gate parts, a server loop that samples each car's position, and per-racer state for the next gate, the lap count, and the split times. The client only displays the results.
Why Touched Events Fail As Checkpoints
The Touched event is the obvious first choice, but it is a weak foundation for a race that ranks players. There are three separate problems, and each one gets worse as cars get faster.
The failure modes include but are not limited to:
- Tunneling. At 250 studs per second, a car can move several studs between the position updates the server actually sees. A one-stud-thick gate can sit entirely inside that gap, so the event never fires.
- Spoofing. If the client detects the touch and fires a RemoteEvent, an exploiter can fire that same remote with any checkpoint index at any time. Server-side Touched helps, but the car's position still comes from the client that owns it.
- No direction. Touched reports contact, not travel. A car reversing through a gate, or clipping the gate's edge on the way to a shortcut, registers the same as a clean pass.
All of these point to the same design. The server decides when a gate is crossed, using geometry it controls.
| Detection Method | Catches Fast Cars | Spoof-Resistant | Direction-Aware |
|---|---|---|---|
| Client Touched + RemoteEvent | Unreliable | No | No |
| Server Touched | Unreliable | Partially | No |
| Server plane-crossing test | Yes | Yes, with plausibility checks | Yes |
Setting Up The Gates
Each checkpoint is an invisible, anchored part with CanCollide, CanTouch, and CanQuery turned off, so it adds nothing to the physics step. Give each one an integer Index attribute, and rotate it so its front face (LookVector) points in the direction of travel.
The finish line is Index 0, and the sector gates run 1 through N around the track. Make each gate a few studs wider than the road on each side — enough to catch a car running wide over the kerb, but not so wide that it accepts a shortcut through the infield.
```lua local Gates = workspace.Track.Checkpoints local function getGates() local list = {} for _, gate in Gates:GetChildren() do list[gate:GetAttribute("Index")] = gate end return list end local gates = getGates() local function signedDistance(gate, position) return gate.CFrame.LookVector:Dot(position - gate.Position) end local function crossedWithinBounds(gate, prevPos, curPos, dPrev, dCur) local alpha = dPrev / (dPrev - dCur) local hit = prevPos:Lerp(curPos, alpha) local localHit = gate.CFrame:PointToObjectSpace(hit) local half = gate.Size / 2 local inside = math.abs(localHit.X) <= half.X and math.abs(localHit.Y) <= half.Y return inside, alpha end ```The signed distance is negative while the car approaches a gate and positive once it has passed. Therefore, a forward crossing is a sign flip from negative to non-negative, and the lerp step confirms that the car went through the gate's rectangle rather than around it.
On every sample, the server measures the car's signed distance to the plane of the next gate. A flip from negative to positive, with the hit point inside the gate's width and height, counts as one crossing.
The Server Sampling Loop
Once the gates exist, one Heartbeat connection drives every racer in the server. It reads the chassis position, tests it against that racer's next expected gate only, and stores the sample for the next frame.
```lua local RunService = game:GetService("RunService") local racers = {} -- keyed by Player RunService.Heartbeat:Connect(function() local now = workspace:GetServerTimeNow() for player, state in racers do local pos = state.chassis.Position local gate = gates[state.nextIndex] local dCur = signedDistance(gate, pos) if state.dPrev < 0 and dCur >= 0 then local inside, alpha = crossedWithinBounds(gate, state.prevPos, pos, state.dPrev, dCur) if inside then local crossTime = state.prevTime + alpha * (now - state.prevTime) onCheckpoint(player, state, crossTime) end end state.prevPos = pos state.prevTime = now state.dPrev = signedDistance(gates[state.nextIndex], pos) end end) ```Notice that the loop only ever checks one gate per racer. This is why skipping a checkpoint does nothing: gate 4 is invisible to the logic until gate 3 has been crossed, so a cut across the infield earns no progress at all.
The interpolation line matters more than it looks. Instead of stamping the crossing with the current frame's time, it estimates the moment the car actually met the plane, which recovers precision that a 16.7 ms frame would otherwise throw away.
Store the per-racer state as a plain table keyed by Player, following the module structure in our Luau scripting patterns guide. Clear the entry on PlayerRemoving so a disconnect never leaves a ghost racer in the loop.
For performance, the loop costs one dot product and a few comparisons per racer per frame. Even a 30-player server spends a tiny slice of its frame budget here, which leaves room for the systems covered in our Roblox server architecture guide.
A car moving at 250 studs per second covers about four studs per 60 Hz frame. Interpolating between the two samples places the crossing inside that frame instead of rounding it to the frame boundary.
Laps, Splits, And Plausibility Checks
Every accepted crossing produces one split, which is the time between this gate and the previous one. The same handler advances the expected index, closes the lap at gate 0, and decides whether the lap still qualifies for the leaderboard.
```lua local SPEED_MARGIN = 1.15 local LAST_INDEX = #gates local function onCheckpoint(player, state, crossTime) local segment = crossTime - state.lastCrossTime local floorTime = segmentLength[state.nextIndex] / (state.maxSpeed * SPEED_MARGIN) if segment < floorTime then state.lapValid = false end table.insert(state.splits, segment) state.lastCrossTime = crossTime if state.nextIndex == 0 then finishLap(player, state) state.nextIndex = 1 elseif state.nextIndex == LAST_INDEX then state.nextIndex = 0 else state.nextIndex += 1 end end ```The segment floor is the key anti-cheat number. segmentLength holds the straight-line distance between consecutive gates, which is always shorter than any line a car can actually drive, so dividing it by the vehicle's top speed gives a time that no legitimate lap can beat.
The 15% margin absorbs slipstream, downhill sections, and replication jitter. Naturally, you should tune it per track, but start strict and loosen it only when real clean laps get flagged.
Each split has a floor: the straight-line distance between gates divided by the car's top speed plus a margin. Any faster split makes the lap ineligible for the leaderboard, though it still counts toward race position.
Teleport And Speed Checks
In addition to segment floors, compare each sample's displacement against what the car could have covered in that time. If a chassis moves more than 1.5 times its top speed multiplied by the elapsed time, mark the lap invalid and log the event rather than kicking the player outright.
Remember that your own respawn system teleports cars too. When the server resets a racer to their last checkpoint, set a skip flag for that sample and reset prevPos, or every respawn will read as a cheat.
Invalidate Laps Instead Of Punishing Players
An invalid lap still counts toward race position, but it never reaches the persistent leaderboard. Repeated flags across sessions are a moderation signal, and our Roblox moderation systems guide covers how to escalate them without auto-banning a player over one noisy reading.
Live Race Position
Race position comes from three numbers each racer already has: laps completed, the next gate index, and the distance to that gate. Sort by laps first, then by gate progress (counting gate 0 as N + 1), then by remaining distance, and you have live standings without any extra physics queries.
Network Ownership: Steering Feel Versus Trust
By default, Roblox gives physics ownership of a vehicle to the player driving it, which is what makes steering feel instant. That said, it also means the position your server samples is a position the client reported.
Calling SetNetworkOwner(nil) on the chassis root makes the server simulate the car, which removes position spoofing entirely. However, every input then travels to the server and back before the car responds, and at 120 ms of ping, racers feel that delay in every corner.
| Ownership Mode | Steering Feel | Position Trust | Best Fit |
|---|---|---|---|
| Client ownership + plausibility checks | Instant | Bounded by checks | Casual races, multiplayer heats |
| Server ownership | Delayed by round trip | Full | Ranked time trials |
| Per-mode switch | Varies by mode | Full where it matters | Experiences with both modes |
For many experiences, client ownership plus the plausibility checks above is the right default. Reserve server ownership for ranked time-trial modes where a record carries real weight, and say so in the mode's UI so players understand why the car feels heavier.
Starting The Race Fairly
A clean timer needs a clean start. The server picks a start timestamp a few seconds in the future, broadcasts it, and holds every car in place until that moment arrives.
Here's how the start sequence fits together:
- Schedule. Set the start time to workspace:GetServerTimeNow() plus three seconds and fire it to every racer. GetServerTimeNow returns a clock synchronized across server and clients, so every countdown hits zero at the same real moment.
- Hold. Anchor each chassis root, or zero the VehicleSeat throttle, until the start time passes. This prevents a jump start rather than trying to detect one after the fact.
- Release. On the first Heartbeat after the start time, unanchor the cars and set each racer's
lastCrossTimeto the start time exactly. Every first split is then measured from the same instant.
Overall, the start is the one moment every racer shares. Get it exactly right before you tune anything else.
Showing Splits Without Trusting The Client
The client still owns how the timer looks, even though it never owns the result. A running clock on screen can be computed locally as GetServerTimeNow minus the start time on every RenderStepped, which stays smooth and lines up with the server.
When the server accepts a split, it fires a RemoteEvent carrying the gate index, the official segment time, and the delta against the player's personal best. The client replaces its local estimate with that value and colors the delta green or red — our Roblox UI systems guide covers building that HUD without rebuilding instances every frame.
Keep the remote one-directional. The client never sends timing data upward, so there is nothing for an exploit to forge.
Yes, a client can show a live timer safely. It computes elapsed time from a synchronized start timestamp for display only, and the official split times the server sends after each gate overwrite that estimate.
Persisting Personal Bests And Leaderboards
Only valid laps reach storage, and they are stored as integers. Convert each lap to milliseconds with math.floor(lapTime * 1000 + 0.5) before writing, because OrderedDataStore accepts integer values only.
Use UpdateAsync rather than SetAsync for the leaderboard entry, and compare the stored value with the new one inside the transform function. As a result, two servers finishing laps for the same player at once cannot overwrite a faster time with a slower one.
Read the board with GetSortedAsync(true, 50) so the lowest time ranks first. Full split arrays belong in the player's regular profile, which our Roblox data stores guide and the companion piece on session locking for player data cover in detail.
Use one leaderboard key per track and car class so the boards stay comparable. A kart record and a supercar record on the same layout are different competitions, so name keys like harbor-kart and harbor-gt rather than mixing them.
Store valid laps as integer milliseconds in an OrderedDataStore, with one key per track and car class. Keep the full split arrays in each player's regular DataStore profile.
Testing The System Before Players Do
Before you open the track, drive it yourself in Studio with a debug overlay that logs every crossing, alpha value, and flagged split. Then run three checks that catch common configuration mistakes:
- Clean lap. Drive a normal lap and confirm zero flags. If a legitimate lap trips a segment floor, either the gate spacing or the top-speed value is wrong.
- Shortcut lap. Cut every corner you can find and confirm that no gate is accepted out of order. Also confirm that no gate is wide enough to catch the cut.
- Teleport lap. Use the command bar to move the chassis mid-lap. Then confirm that the displacement check invalidates the lap and that a scripted respawn does not.
Run all three after every track edit. A single moved gate can open a shortcut that no one notices until it shows up at the top of the leaderboard.
Build The Rest Of The Race
Once checkpoints, laps, and splits are validated on the server, most of the remaining work is presentation: a chase camera, a results screen, and a lobby that queues racers into heats. Our Roblox camera systems guide picks up the chase cam from here.
If you are planning a full racing experience, build it in order: the vehicle, then the timing layer, then the camera. After all, each piece depends on the one before it.
Frequently Asked Questions
These answers cover the edge cases builders run into once the core timing loop works. Each one assumes the server-side gate design described above.
Why not use Touched events to detect checkpoints in a Roblox race?
Touched can miss a thin gate when a fast car moves several studs between position updates, and it fires for wheels and debris alike. A server plane-crossing test catches every pass and also knows which direction the car went.
Should Roblox race cars use server network ownership?
Casual races should keep client ownership so steering feels instant. Ranked time trials can call SetNetworkOwner(nil) to remove position spoofing, at the cost of a full round trip of input delay on every steering change.
How should lap times be saved in an OrderedDataStore?
Save integer milliseconds, since OrderedDataStore only accepts integers, and write through UpdateAsync so a slower lap never overwrites a faster one. Read with GetSortedAsync(true, 50) so the lowest time ranks first.
How do you rank racers' live positions during a multi-lap race?
Sort by laps completed, then by next gate index with the finish gate counted last, then by distance to that gate, shortest first. All three values already live in each racer's server state, so standings cost no extra physics.
How do you stop respawns from triggering the anti-cheat checks?
When the server moves a car back to its last checkpoint, set a skip flag for the next sample and reset the stored previous position. Otherwise the displacement check reads every respawn as a teleport and voids the lap.


