AI Game Maker for Roblox: What a Generated Game Can and Cannot Do There
Short answer: a generated game arrives as one loop for one player. Roblox runs that loop on a server every player shares, and hands each player an untrusted copy of it. So the loop survives the trip and the bookkeeping does not: score, health, inventory, and the leaderboard are all claims made by a device Roblox does not trust. Three seams decide whether the result is a Roblox experience or a single-player demo that breaks the moment a stranger joins — who owns the number, who owns the object, who owns the clock — and the leaderboard is where all three become visible to every player at once. Fix them and a generated game is genuinely playable on Roblox. Skip them and it works perfectly until the second player arrives, which on Roblox is the default condition rather than a mode you switch on.
One clarification before the technical part, because it changes what "there" means. Almost no AI game maker publishes to Roblox. The web tools emit HTML5 and JavaScript; Roblox runs Luau inside Studio, on its own engine, with its own services. There is no export button, and there will not be one, because the output formats have nothing in common. What transfers is the design — the loop, the numbers, the win condition — and the Roblox build is a rewrite of it in Luau. That rewrite is where the authority model gets decided, and it is the part the generator never had to think about.
Roblox's default is the opposite of a generated game's default
The docs are blunt about this: games on Roblox are multiplayer by default and run in a client-server model, and the server is the ultimate authority for maintaining state. When you publish, Roblox copies your data model to its servers as the runtime model; each connected client gets a copy of that model, renders it, and runs the scripts that are allowed to run there. Replication keeps the copies in sync — data, physics, and chat.
A generated game assumes the opposite arrangement. It assumes one process, one player, one copy of the truth, and no latency. Every one of those assumptions is false on Roblox.
| Generated game assumes | Roblox actually does |
|---|---|
| One copy of the state | One server copy plus N client copies, continuously reconciled |
| The player's device is the program | The player's device is a viewer that also runs scripts you must not trust |
| Actions happen when the code runs | Actions happen 100–300 ms later, and the order two players' actions arrive in is not the order they happened in |
| Score and health are variables | Score and health are replicated properties, and only one side of the boundary gets to be right |
That latency figure is from Roblox's own documentation, and it is the number to design against: most players are between 100 and 300 milliseconds from the server. Studio's playtest runs at zero latency by default, which is why a generated game feels fine in the editor and feels wrong on a phone. Set network simulation to 200 ms in both directions before you judge anything — the docs suggest 50–150 ms as a minimum simulation, but 200 ms is closer to the median player.
The four-bucket audit
Before changing a line, sort every line the generator wrote into four buckets. This takes about twenty minutes and it replaces the vague feeling that "the multiplayer doesn't work" with a list.
| Bucket | What belongs there | What it is allowed to decide |
|---|---|---|
| Server-owned | Score, health, inventory, currency, round state, spawns, ranking writes | Everything that another player can see or that survives a respawn |
| Client-owned | Camera, input, UI layout, sound, local animation, aim preview | Everything that affects only what this player perceives |
| Shared read-only | Positions, animations, and values replicated from the server | Nothing — read it, never write it |
| Wrong side | Anything from bucket 1 that the generator put in a LocalScript | Nothing, and it is the bug |
The fourth bucket is where generated Roblox code fails, and it fails in a small number of recognisable shapes. These are the lines to search for:
| Line the generator wrote | Where it usually lands | With one player | With two |
|---|---|---|---|
player.leaderstats.Coins.Value += 1 | A LocalScript next to the coin | The counter goes up | It goes up only on that player's screen; everyone else sees zero, and it snaps back on respawn |
game.Players.LocalPlayer | A Script under ServerScriptService | Errors immediately, so you catch it | Same error, but only when someone finally plays with a friend |
hit.Parent:FindFirstChild("Humanoid") inside Touched, then part:Destroy() | A server Script | One coin, one destroy | Two Touched events can fire before the destroy replicates; the second handler reads a destroyed part |
while task.wait(1) do timeLeft -= 1 end | A LocalScript | A countdown | N countdowns, all drifting apart |
humanoid.Health = 0 | A LocalScript | The enemy dies on your screen | The enemy is alive on everyone else's, and the server keeps it alive |
workspace.CurrentCamera.CFrame | A server Script | No visible effect | Same, but now you have shipped a camera that ignores input |
The reason these are so consistent is that the generator is optimising for the shortest code that produces the described behaviour in a single-player preview. In a single-player preview, a LocalScript that increments a counter is correct. It is only wrong relative to a boundary the prompt never mentioned.
Seam one: the number
Every generated game has one number the player watches. Coins, score, distance, kills. The first seam is deciding which side of the boundary owns it, and the answer is always the server, for a reason that has nothing to do with cheating: the client's copy is a copy, and copies get overwritten. A LocalScript that raises a counter is not lying to the server; it is writing to a value that the next replication pass will replace. The symptom is not "the score is wrong." The symptom is "the score goes up and then goes back."
The test is one line and one observation. Have player B watch player A's counter while A collects a coin. If B sees nothing, the counter is client-owned and the game has no shared score at all.
The fix is to move the write to the server and let the client send intent. In practice that means the coin's Touched handler lives in a server Script, and the client never sends a number — it sends an action. A client that can say "add 50 coins" is a client that will eventually say it.
-- ServerScriptService/Coins.server.lua
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local grantCoin = Instance.new("RemoteEvent")
grantCoin.Name = "GrantCoin"
grantCoin.Parent = ReplicatedStorage
Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = stats
end)
-- The client asks; the server decides. No amount crosses the boundary.
grantCoin.OnServerEvent:Connect(function(player)
if not player:FindFirstChild("leaderstats") then return end
player.leaderstats.Coins.Value += 1
end)
Two details matter more than the code. Validate the argument even when there is no argument — check that the caller has a character, is alive, and is not firing the event forty times a second. And create leaderstats on the server: the built-in player list only reads a Folder named exactly leaderstats parented to the Player, with IntValue children, and a LocalScript cannot create one that anyone else sees.
Seam two: the object
The second seam is the shared object: a coin, a door, a power-up, an NPC. In a single-player build, "the player touched it" is unambiguous. On Roblox, Touched fires for every character that intersects the part, on the server, and both handlers run before the part's destruction has replicated to anyone. So the first player collects the coin, the second player's handler reads a part that is already being destroyed, and you get either a double grant or a nil index error, depending on timing.
The fix is to make the claim atomic on the server: check, mark, then destroy.
local claimed = false
part.Touched:Connect(function(hit)
if claimed then return end
local character = hit.Parent
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health <= 0 then return end
claimed = true -- the claim happens before anything yields
part.CanTouch = false
part.Transparency = 1
part:Destroy()
end)
The load-bearing line is claimed = true before the destroy, not after. Anything that yields between the check and the claim — a task.wait, a DataStore call, a :WaitForChild — reopens the window. This is the same class of bug as a double-click on a buy button, and it is the most common multiplayer bug in generated Roblox code, because a single-player build never has two claimants.
The second half of this seam is ownership of things that move. If a generated game has a moving platform, a vehicle, or a physics-driven prop, Roblox assigns network ownership of that assembly to one client by default. That client's physics becomes the authority for everyone else. For a platform that carries players, this is usually fine and occasionally catastrophic — the owner walks away and the platform stutters for everyone. Generated code never sets network ownership because a single-player build has no one to hand it to. If the game has physics props, decide per prop: anchored and server-driven, or unanchored and client-owned, never "whatever the default did."
Seam three: the clock
Timers, countdowns, round state, cooldowns. A generated countdown is a loop on the client, and N clients running N loops produce N different clocks within seconds. Then the round ends at a different moment for each player, and someone gets a "you lost" screen while still holding the flag.
The rule: one clock, on the server, broadcast as a number. The server owns the deadline; clients render the difference between the deadline and their own workspace:GetServerTimeNow(), which is synchronised. Clients do not decrement anything.
-- server
local roundEndsAt = workspace:GetServerTimeNow() + 120
-- broadcast roundEndsAt once, then let clients compute the remainder
This also fixes the case that looks like a networking bug and is not: a countdown that "jumps" when a player joins mid-round. If the client computes the remainder from a shared deadline, a late joiner sees 47 seconds left. If the client starts its own loop at join, the late joiner sees 120 and the round is already over.
Identity: "the player" does not exist on the server
The smallest seam, and the one that produces the most confusing errors. game.Players.LocalPlayer is nil in a server Script, always. Generated code that says LocalPlayer in a handler that ends up on the server does not fail at publish time; it fails the first time the handler runs, with an error about indexing nil. If the handler only runs when two players interact, you will not see the error in a solo test at all.
The fix is to pass the player explicitly. Touched gives you a character, and Players:GetPlayerFromCharacter(character) gives you the player. RemoteEvent.OnServerEvent gives you the player as the first argument, always, and that argument cannot be spoofed — it is set by the engine, not by the caller. Any player identity that arrives as a second argument from the client can be spoofed, and should be treated as a claim.
The leaderboard, in three tiers
This is the part of the gap that decides whether the game has a reason to be played twice, and it is also the part where generated code is most confidently wrong. A leaderboard is not a UI element. It is a promise about persistence, and the promise has a price in requests per minute.
| Tier | What it is | Cost | Honest label |
|---|---|---|---|
| 0. Session board | leaderstats only, in-memory, resets when the server closes | Zero DataStore calls | "This server's top score" |
| 1. Persisted on leave | One write per player on PlayerRemoving, read back on join | P writes per server shutdown | "Your best, saved" |
| 2. All-time board | OrderedDataStore plus a batched write loop plus a timed read | Bounded by the ordered-write budget | "Global all-time" |
Most generated Roblox games ship tier 0 and describe it as tier 2. That is not a technical failure; it is a labelling failure, and it costs you the players who come back the next day expecting their score to still be there. Tier 0 is a perfectly good first week. Just call it what it is.
Tier 2 is where the numbers bite. These are the published limits at the time of writing, and they are worth re-reading before you size anything, because they have changed before:
| Limit | Value |
|---|---|
| Ordered writes, per server, per minute | 30 + numPlayers × 5 |
Ordered list reads (GetSortedAsync), per server, per minute | 5 + numPlayers × 2 |
| Standard reads / writes, per server, per minute | 60 + numPlayers × 40 |
| Experience-wide writes, per minute | 300 + concurrentUsers × 20 |
| Per-key throughput | 25 MB/min read, 4 MB/min write, rounded up to the next KB |
| Key name / value size | 50 characters / 4 MB per key |
GetSortedAsync page size | 1 to 100, integers only |
UpdateAsync | Counts against both the read and the write budget |
Two consequences follow, and neither is obvious from the API.
The per-server ordered budget binds first. At 20 players, a server gets 130 ordered writes per minute. The experience-wide write budget at that concurrency is 700. The per-server number is the one you hit, and it scales at 5 per player while the experience budget scales at 20 per concurrent user — so adding servers does not buy you headroom. The binding constraint is always the single server's share.
Write-per-event does not fit. Twenty players collecting one coin every two seconds is 600 writes per minute against a 130 budget: 4.6× over. The failure mode is not a clean error; it is DatastoreThrottled and KeyThrottled appearing intermittently under load, which reads as "the leaderboard is flaky" and is actually "the leaderboard is 4.6× oversubscribed."
The fix is batching, and the arithmetic is the whole argument:
| Approach | Writes per minute, 20 players | Share of 130 budget |
|---|---|---|
| Write on every coin (1 coin / 2 s / player) | 600 | 462% — throttled |
| Write each player's total every 30 s | 40 | 31% — comfortable |
| Write on leave plus a 60 s checkpoint | ~20 plus 20 per shutdown | 15% — cheapest safe option |
Thirty seconds of lost progress is a much better trade than a board that silently stops updating. And if you use UpdateAsync, remember it charges you twice — read plus write — so a batched UpdateAsync every 30 seconds is still cheaper than a SetAsync every 2 seconds by an order of magnitude.
Reading the board is also a budget decision
The list budget is the smallest of the four: 5 + numPlayers × 2 per minute, which is 45 at 20 players. Refresh a top-ten board every second and you are at 60 — over budget before you have done anything else with the store. Every two seconds is 30, which fits. Every five seconds is 12, which leaves room for the rest of the game.
Two rules that come out of this. Read the board on a timer, never per frame, and never per player — one read serves the whole server. And display the refresh interval, or at least don't pretend the number is live: a board that updates every five seconds is honest if the UI says "updated 3s ago," and dishonest if it looks real-time and isn't. The same applies to GetAsync caching, which can return a value that is behind the backend; if the number on screen is a ranking, a stale read is a wrong ranking, and the only defence is to make staleness visible.
Two servers, one row
Sooner or later the same player's row is written by two servers — they rejoin fast, or a shutdown overlaps a join. SetAsync is last-write-wins, and "last" is decided by arrival order, not by which value is better. The docs recommend UpdateAsync for exactly this reason: it reads the current value and lets you decide.
For a ranking, the decision is almost always math.max:
store:UpdateAsync("alltime:" .. userId, function(old)
return math.max(old or 0, newScore)
end)
That single line makes out-of-order writes harmless, because a late-arriving lower score cannot overwrite a higher one. It also means a player's record never goes down, which is the property that makes an all-time board believable. Without it, a crash during shutdown can lower a record, and the player who notices will never trust the board again.
One more rule, and it is the one that saves the most pain: never rank the key you save progress in. Progress can be reset, migrated, or corrected; a rank cannot. Keep save:<userId> for the game state and alltime:<userId> for the ranking metric, and let the ranking metric be monotonic by construction. If the metric is bounded — best time, accuracy, fewest moves — ties are constant, and OrderedDataStore has no defined order for equal integers, so the board reshuffles between reads. Rank on a metric with a long tail (lifetime coins, total distance) or accept that the top ten will visibly reorder itself.
The two-client test
None of the above is visible with one player. The test is Studio's multi-client playtest: two clients, network simulation at 200 ms in both directions, and six checks in this order.
- Shared score. Player B watches A's counter while A collects. B must see it move.
- Single claim. Both players touch the same pickup in the same second. Exactly one grant, no error in the server output.
- Clock agreement. Both clients show the same remaining time, within a second, at the same moment.
- Damage authority. A takes damage; B must see A's health change, and A must not be able to change B's.
- Late join. Join mid-round. The countdown must show the real remainder, not a fresh one.
- Rejoin. Leave and rejoin. The saved value must be there, and the board must not have gone backwards.
If a check passes with one client and fails with two, the bug is in the authority split, not in the feature. That distinction is worth stating out loud, because the instinct is to debug the feature.
What to paste back into the generator
Generated code is usually one repair away from being correct, if the repair names the boundary. Six clauses, each closing one seam:
- "All score, health, inventory, and currency changes must happen in a Script under ServerScriptService. No LocalScript may write a value another player can see."
- "The client may only send intent through one RemoteEvent. It must never send an amount, a price, or another player's name."
- "Validate every RemoteEvent argument on the server: type, range, and rate. Reject silently rather than erroring."
- "A pickup must be claimed atomically on the server: set a claimed flag, then destroy. Do not yield between the check and the claim."
- "Round state and timers live in one server script and are broadcast as a deadline. Clients compute the remainder and never decrement a shared value."
- "Ranking writes go through UpdateAsync with math.max so a late write cannot lower a record. Progress saves and ranking metrics use separate keys."
The clauses work because they describe a boundary rather than a behaviour. "Make it multiplayer" is not actionable; "no LocalScript writes a value another player can see" is a rule you can grep for.
What this does not fix
Five limits, stated plainly, because a method that claims to cover everything gets abandoned at the first surprise.
It is not anti-cheat. Server authority stops score forgery. It does not stop aimbots, speed exploits, or a client that refuses to render what it is told. Those are a different discipline, and for a small generated game the honest position is that you are protecting the leaderboard's integrity, not the game's.
It is not matchmaking. A single server's board is a session board until it is persisted, and persistence is not matchmaking. Cross-server play, party joining, and skill-based grouping are separate systems that Roblox provides primitives for and does not assemble for you.
It does not fix physics ownership. Network ownership of moving assemblies is a per-object decision, and the default is not the same as the right answer.
It does not replace the save system. The seams here are about values that other players can see; the seams around saving a player's own progress — lifecycle events, serialisation, schema drift after a regeneration — are a different set, covered in [where a generated game's state actually breaks](/ai-generated-video-game).
It does not make the assistant write the boundary for you. Roblox's own Studio tooling has moved well past code completion, toward planning and testing a build. That changes who writes the first draft. It does not change who owns the decision about which side of the client-server line a number lives on — and a model that has not been told will put that number wherever the shortest sample code put it, which is the client.
The rule that survives all five: count the seams before you count the features. A generated Roblox game with three features and three closed seams is playable with strangers. A generated Roblox game with thirty features and an open seam is a demo that works until someone else joins — and on Roblox, someone else always joins.