A player destroyed every enemy ship, lost none of their own, and the game called it a defeat. This is how I worked out why, fixed it at the root, and proved the fix, without ever reproducing that fight.
Game
Idle Galactic Conquest, live on Roblox
Area
Battles the server checks by replaying them
The suspect
Maths that differs in the last bit between platforms
The result
Battles that replay identically on every device
01
How a battle is judged
Battles in this game decide real things: territory in the galaxy, raids on other players’ credits, an alliance event. So the result on a player’s screen is never trusted. Every order they give is recorded with the tick it happened on, and the server fights the whole battle again from that log, with the same random seed. The server’s result is the verdict.
You fight iton your device
Your orderstick by tick
The server fights it againsame seed, same orders
Its result countsnever the client’s
That makes a faked win impossible. It also means the replay has to land exactly where the player’s fight did, on every device, every time.
02
The report
A player posted the result screen in the game’s Discord: every enemy destroyed, none of their own ships lost, and a defeat. The obvious guess is a scoring bug, and that’s where most fixes would have stopped.
Defeat
Enemies destroyed
4 / 4
Your ships lost
0 / 3
03
What the evidence said
The battle summary had no hull damage on it at all. In this game that only happens one way: the server’s replay ran out of orders while the battle was still going, and was marked unfinished. So the scoring was right. The server had simply fought a different battle from the one on the player’s screen.
Not a scoring bug: a desync. Somewhere, the player’s device and the server stopped agreeing on what happened.
04
One cause, already found
A week before, while building a test harness for the battle engine, I’d found one way this could happen. Every battle drew its random numbers from a single generator the module shared. On a player’s device that’s harmless: one battle at a time. On the server, replays pause halfway through and run side by side, so a second replay starting could reseed the first one’s generator underneath it.
The fix was for every battle to own its generator. The harness now proves it: it fights a battle the way a player would, then replays it alone, interrupted by another battle, and against a damaged fleet. That bug was already gone before the report came in, so something else was still out there.
05
The suspect: one bit
Roblox servers run on Linux. Players fight on Windows, Macs, phones and consoles. Adding, multiplying and square roots give the same answer everywhere, down to the last bit. Sine, cosine and arctangent come from each platform’s own maths library, and they don’t have to. On phone chips, a multiply and an add can also be fused into a single rounding.
Player’s device0.7071067811865476
Server0.7071067811865475
An illustration of the size: one part in about ten quadrillion.
That’s tiny, but a battle is thousands of steps, each feeding the next. A ship turns a hair differently, a shot that grazed now misses, the random sequence shifts by one draw, and from there it’s a different fight.
the player’s battlethe server’s replay
I couldn’t recreate the reported battle, so I modelled the effect instead. Nudging 2% of the inputs by one last bit changed 2 battles in 30 and flipped none of their results. But one nudge in a close, 166-second fight flipped the winner. Rare, real, and exactly what the player saw.
06
The fix, in three parts
1Maths that’s identical everywhere
Every value that affects the outcome is now built only from steps that are exact on every platform. Sine, cosine and arctangent are fdlibm’s kernels written out in plain Luau, angles wrap with a floor instead of a decimal remainder, and random ranges are scaled by hand. Cosmetic effects draw from their own generator and can use anything.
2A replay that plays on
If the replay reaches the end of the player’s orders with the battle still going, it now plays on with no new orders, for up to a quarter of the fight’s length and never more than 30 seconds, until the battle ends by itself. A small drift near the end no longer turns into an unfinished fight.
3Counters for what I can’t see
Every replay that disagrees with the player, gets saved by playing on, or still ends unfinished is counted in the game’s telemetry. A desync on any device now shows up as a number on my dashboard, not a confused post in Discord.
SimulateEngine · sine, without the platform’s maths library
local function ksin(x)
local z = x * x
local v = z * x
return x + v * (S1 + z * (S2 + z * (S3 + z * (S4 + z * (S5 + z * S6)))))
end
-- x = k * pi/2 + r, |r| <= pi/4, with pi/2 split in two so k * PIO2_1 is exact
local function reduce(x)
local k = math.floor(x * INVPIO2 + 0.5)
local r = x - k * PIO2_1
r = r - k * PIO2_1T
return r, k % 4
end
local function sin(x)
local r, n = reduce(x)
if n == 0 then return ksin(r) elseif n == 1 then return kcos(r) elseif n == 2 then return -ksin(r) end
return -kcos(r)
end
07
How it was proved
5 / 5
Determinism checks pass: the same battle replayed alone, interrupted by another, and against a damaged fleet, ending exactly where the player’s did.
0
Calls to the platform’s sine, cosine, arctangent or power left in the code that decides a battle. The engine is searched for them after every change.
“Fixed”
The player who reported it later said the false defeat no longer happens.
08
What it shows
Don’t trust the client, and make the server’s check exact. A check that’s right on one platform and wrong on another is a bug that only some players ever hit.
When you can’t reproduce a bug, model it. Then fix the whole class of cause and add a counter, instead of waiting for the next report.
Prove fixes with a harness, not a feeling. The same checks run after every change to the battle engine.
Got something in your game that works on one device and not another, or results players don’t trust?