Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

How I Built a Fast Roblox Pet Calculator in Next.js 16 (Formulas, Multi-Mutations & Clean UX)

A lot of fan-made gaming calculators on the web suffer from the same problems: heavy 3D bundles, clunky sliders that fight you when typing, slow servers, and popups everywhere. I wanted to build a fast, lightweight comp

A lot of fan-made gaming calculators on the web suffer from the same problems: heavy 3D bundles, clunky sliders that fight you when typing, slow servers, and popups everywhere.

I wanted to build a fast, lightweight companion tool for the Roblox game Steal an Egg that loads instantly on mobile and handles all the math cleanly in the browser. You can try the live app here: Steal an Egg Calculator.

Here is a quick breakdown of the game math and a few small UX decisions that made a big difference.

1. Modeling the Pet Income Formula in TypeScript

In Steal an Egg, every pet has a base income per second (from $1/s for a Chicken up to billions per second for end-game Divine pets). Two things scale that number:

  1. Size scale (weight / base weight)
  2. Mutations (multipliers like Silver Γ—1.2, Golden Γ—2.5, Fractured Γ—2.75, up to Rainbow Γ—3.5)

The interesting part is that size scaling isn't linear. Up to 125x scale it follows scale^(37/60), and above the 125x soft cap the curve flattens out to scale^(2/5) * 125^(13/60).

Writing that as a pure TypeScript helper keeps the calculation fast and easy to test:

const WEIGHT_SOFT_CAP = 125

export function sizeMultiplier(scale: number) {
  if (scale <= 0) return 0
  if (scale <= WEIGHT_SOFT_CAP) return Math.pow(scale, 37 / 60)
  return Math.pow(scale, 2 / 5) * Math.pow(WEIGHT_SOFT_CAP, 13 / 60)
}

export function petIncome(baseIncome: number, scale: number, mutationMultiplier: number) {
  return baseIncome * sizeMultiplier(scale) * mutationMultiplier
}

2. Supporting Multi-Mutation Stacking

Instead of forcing users to pick only one mutation from a dropdown, I used an array of selected mutation IDs and reduced them multiplicatively:

const selectedMutations = MUTATIONS.filter((m) => mutationIds.includes(m.id))
const mutationMult = selectedMutations.reduce((acc, m) => acc * m.multiplier, 1)

Clicking Normal resets the array to [] (Γ—1), while toggling multiple mutations (for example Golden Γ—2.5 + Rainbow Γ—3.5) immediately updates the combined multiplier (Γ—8.75) and shows the live /s, /min, /hr, and /day earnings.

3. Fixing the Annoying Number Input UX

One tiny detail that drives users crazy in web calculators is using <input type="number"> with onChange clamping directly to a numeric state. The moment someone tries to backspace 1.5 to type 27.49, the field snaps to 0.1.

Keeping a separate scaleInput string state and only clamping on onBlur fixes this completely:

const [scaleInput, setScaleInput] = useState('1')
const parsedScale = Number(scaleInput.replace(',', '.'))
const scale = Number.isFinite(parsedScale) && parsedScale > 0 ? Math.min(500, parsedScale) : 1

Supporting both . and , also helps European mobile users who have a comma on their numeric keypad.

4. Keeping the Architecture Lean

Instead of dumping everything into a single fragile SPA with hash URLs, I split the app into focused static routes in Next.js App Router:

  • / - Main Value & Income Calculator
  • /pets - Searchable list of all 290 pets ranked by base income
  • /hatch-time-calculator - Hatch speed with 2x Gamepass and online 30x bursts
  • /fuse-calculator - Fuse Machine cost and size bias
  • /rituals - Steal an Egg Rituals Calculator for end-game weight conversions
  • /biomes, /egg-finder, and /mutations

Every page prerenders cleanly, uses loading="lazy" with explicit width/height attributes to prevent layout shift, and runs all calculations client-side with zero backend latency.

If you're building niche gaming tools or calculators, keeping the bundle small, avoiding unnecessary backend dependencies, and getting the small input details right goes a long way. Feel free to check out Steal an Egg Calculator and let me know if you spot any edge cases!

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.