How to make a multiplayer game with AI
On this page
Getting two browser windows to talk to each other is pretty easy for an agent. Keeping a whole room of players smooth and fair is harder, because a first build can work fine on localhost and then fall apart once players join from somewhere else.
That’s why it’s worth naming an authoritative server, prediction, reconciliation and interpolation in your very first prompt. Between them, those four decide who owns the state and how players see each other move.
What breaks in AI-written netcode
Endel Dreyer, who created the Colyseus game server, had Claude Opus 4.5 write a multiplayer shooter from one prompt. It actually ran, but once it was deployed, it sent too much data to stay playable as players joined (Dreyer).
What made the difference was sending each bullet once, as a start position and angle, and sending each player only what was near them.
| Shooter build | Connections |
|---|---|
| First deployed build | Unplayable above 10 clients |
| After reducing the data sent | 100 connections |
Tejas Kulkarni built a 1v1 browser shooter with Grok 3 and Cursor, and he called multiplayer playtesting and feeding problems back to the model “the most time consuming part of the process”. Stale browser windows kept reconnecting to running games until the prompt added an “Enter Game World” button.
One bug even showed a player a duplicate copy of themselves (Kulkarni).
Let the server own state and clients predict movement
Ask for an authoritative server with client-side prediction, reconciliation and interpolation. If those sound like jargon, Gabriel Gambetta’s three-part series explains all four really well, and the terms below come from it (architecture, prediction, interpolation).
1. Authoritative server. The server runs the game, and it’s the one that owns the state.
Clients only send inputs like “left pressed”, never positions, because a client that reports its own position can report any position.
2. Client-side prediction. Waiting for the server makes your own moves feel laggy, so the client applies its inputs at once and numbers each one. Ask for the movement code in one shared module that client and server both run, or the prediction drifts.
3. Reconciliation. The server replies with the last input number it processed. The client drops acknowledged inputs and replays the rest on top of the server’s state, and if you skip this step, you get rubber-banding.
4. Interpolation. It sounds funny, but other players are drawn slightly in the past (100 milliseconds in Gambetta’s example of a server that updates 10 times a second), so they move smoothly between two updates instead of jumping on every packet.
Put all four in the first prompt, along with a tick rate. Colyseus’s fixed-tickrate tutorial simulates at 60 ticks per second and processes the queued inputs on each tick (Colyseus), and a prompt like this one covers it.
Build online multiplayer with an authoritative server. Clients send numbered inputs only. The server runs the simulation at a fixed 60 ticks per second and sends state patches 20 times per second. Movement code lives in one module shared by client and server. The client predicts its own player and reconciles with the server’s last processed input. Other players are interpolated 100 ms in the past.
Which multiplayer stack should you pick?
Colyseus suits most real-time games, while Playroom Kit fits a game that shouldn’t need a server of yours at all. The prices below come from each vendor’s page as of September 2026.
| Stack | What it is | Cost | Good for |
|---|---|---|---|
| Colyseus | Open-source Node.js server for authoritative game rooms, with state sync | Free to self-host; cloud from $15 a month | Most real-time games |
| PartyServer on Durable Objects | Rooms on Cloudflare’s edge, one object per room | Free plan: 100,000 requests a day, SQLite-backed objects | Small rooms, global players |
| Socket.IO | Messaging with reconnects, rooms and fallbacks; you write the game logic | Free, self-host | Turn-based and casual games |
| Playroom Kit | Hosted multiplayer, no backend of yours | Free for 10 users a day; $10 a month for 10,000 monthly users | Party games and prototypes |
| PeerJS | Peer-to-peer WebRTC | Free signaling server | Two friends, no server |
The table draws on Colyseus, Colyseus pricing, PartyServer, Durable Objects pricing, Socket.IO, Playroom and the PeerJS FAQ.
Colyseus keeps the state on the server, and @colyseus/schema sends clients only the properties that changed (state sync). Its team counted 48 of the 945 Vibe Jam 2026 entries built on it (Colyseus blog), which is a pretty solid showing. You can start with npm create colyseus-app@latest ./my-server (docs).
PartyServer is Cloudflare’s library for real-time rooms on Durable Objects, from its PartyKit repo (repo). Deploy it with Wrangler directly, because an issue open since June 2026 reports that new deploys to hosted PartyKit fail with a domain-limit error (issue #985).
On Durable Objects, keep an eye on hibernation, because it’s a little sneaky. Hibernating WebSockets stop duration charges, but a setInterval game loop keeps the object awake, so on the free plan, only run the loop while players are connected (WebSockets guide).
PeerJS is tempting because there’s no server. Its free cloud server only handles signaling, though, and two players behind symmetric NATs can’t connect at all unless you configure a TURN relay (PeerJS FAQ).
With no server, one player’s browser is the authority, so cheating and a host who closes the tab are your problem.
In Godot, web exports have no low-level networking (web export docs), but the WebRTC classes, WebRTCMultiplayerPeer included, are built into HTML5 builds, so luckily the high-level multiplayer API still works (WebRTC docs).
And the four ideas above apply just the same.
Send less data, less often
Both fixes that took Dreyer’s shooter from 10 clients to 100 cut the data it sent, so ask the agent for these four.
-
Events instead of frames. “Fired at angle 42” is one message, while a bullet’s position every tick is sixty a second.
-
Deltas only. Colyseus sends only changed properties by default, but with Socket.IO you write that yourself.
-
Interest management. Each player gets only what’s near them. Dreyer’s shooter needed a spatial index for this before it scaled.
-
Twenty patches a second. Colyseus’s default patch rate is every 50 milliseconds (rooms), and interpolation hides the gaps.
Test with two players on day one
Open the game in a normal window and a private one, or in two browser profiles, so each player has its own storage. The tricky part is that two tabs of one window share localStorage, so a game that keeps its player ID there sees one player twice.
In an automated test, two Playwright browser contexts do the same job (browser contexts), and playtesting games with AI shows the setup.
Then have the agent add a switchable 100-millisecond delay to the server’s outgoing messages, and play again. A game that feels fine on localhost can fall apart at that latency.
Close a window mid-round too, and decide what a dropped player gets back. Colyseus’s allowReconnection() lets a dropped client return to its room within a time window (rooms), while Kulkarni’s “Enter Game World” button stops forgotten windows from rejoining on their own.
Choose chat or emotes before submitting to a portal
CrazyGames and Poki both restrict chat. CrazyGames wants your chat to turn off when the player’s settings say so, and it requires moderation, with a profanity filter as the minimum. It also places the first player of a party straight into a new private room (CrazyGames).
Poki doesn’t even allow chat at all, because it exposes younger players to real risks, and it suggests an emoji system instead (Poki).
So if you build in emotes or preset messages from the start, one build fits both portals, which saves a lot of hassle.
Test it, then ship it
Playtesting games with AI covers automated tests with two players, and where to publish a browser game goes through the portals and their multiplayer rules.
If you want characters that talk, AI NPC dialogue for browser games adds a model proxy with spending caps, then checks proposed character actions against the authoritative game state.
Can AI make multiplayer games? looks at five kinds of multiplayer in the catalog and which tools built them. And you can play the online multiplayer games in the catalog and rate the ones you try, since player votes move them up or down the list.
Games to look at
, Phone friendly , Online multiplayerKurve Royale
Fly a trail-leaving craft and outlast rival pilots inside a shrinking dome.
, Phone friendly , Online multiplayerStarpit.io
Grow from a brown dwarf into a black hole by devouring rival bodies online.
, Phone friendly , Online multiplayerSumoBall.io
Bump rival sumo balls off the arena to be the last one standing.
, Online multiplayerLand Capture
Fight alongside your team to claim more of a shared island than four rival teams.
Questions
Can AI make a multiplayer game?
Yes. Eyrie's co-op shrine defense and little flock's shared sheep farm show two pretty different ways to play together. The hard part is netcode that stays smooth and fair with many players, and that goes better when the first prompt names the architecture.
What is the easiest way to add multiplayer to a browser game?
A hosted service like Playroom Kit, which needs no server of your own. For more control, Colyseus is an open-source Node.js game server, and PartyServer runs rooms on Cloudflare Durable Objects. Peer-to-peer with PeerJS works for two friends, but one player's browser runs the game.
Why do AI-written multiplayer games lag or break?
A first version tends to send too much state, too often, and to trust whatever each client reports. The fixes are the classic ones, which means a server that owns the game, inputs instead of positions from clients, prediction for your own moves, interpolation for everyone else's and sending only the data that changed.
How do I test a multiplayer game alone?
Open a normal and a private browser window, or two browser contexts in one Playwright test, and join the same room. Then add about 100 milliseconds of delay to the server's messages, because a game that works on localhost can fall apart once packets take that long.