Lesson 4 of 11
Data-driven content: designers edit data, not code
Turn Beacon Yard's flat Config constants into items and enemies as JSON data: Rojo JSON modules, kinds in code and rows in data, a validator with design rules that fails CI through Lune, a generated ItemId type, and where Experience Configs fit.
By the end you can
- Separate content (rows of data) from behaviour (code that handles each kind of row)
- Move Beacon Yard's items and enemies into JSON files that Rojo turns into modules
- Write a validator that reports every broken row and runs in CI through a Lune script
- Generate Luau types from the data so a typo in an item id fails the type check
Before this: One source of truth: replicated state, Core loop design: act, reward, spend, repeat, Continuous integration: every check, blocking
Step 1 of 10
A repair kit, and the seven files it touches
Beacon Yard keeps every gameplay number in one module, which was the right first step:
SPEED_PRICE = 25,
SHIELD_PRICE = 40,
COIN_PACK_COINS = 50,
But numbers are only part of an item. The shop service knows each item by name, in code:
function ShopService.purchase(player: Player, item: unknown)
if item == "Speed" then
buySpeed(player)
return
end
if item == "Shield" then
buyShield(player)
return
end
if item == "CoinPack" then
MonetizationService.prompt(player)
return
end
if item == "SpeedPass" then
PassService.prompt(player)
Search src/ at m14-ship for every file that mentions the Shield item (its price constant, the string "Shield" or its label key). A repair kit built the same way would touch the same files. How many are there?
Step 2 of 10
Rows in data, kinds in code
The split is simple to say: data lists the things, code handles each kind of thing. An item row says { id = "RepairKit", kind = "consumable", price = 30, currency = "Coins", labelKey = "shop.repair" }. The shop service has one function per kind: an upgrade is bought once and kept, a consumable is bought and used up, a pass or pack opens a Robux purchase. A row can reuse a kind handler. At m15-scale the buttons are still written by hand and coin items use effects keyed by id. The upkeep and rebuild kinds arrive at m16-design-pass.
| In the picture | In Roblox |
|---|---|
| A line on the menu board | A row in items.json: id, kind, price, currency, labelKey |
| A cooking technique the kitchen knows | A kind the code handles: upgrade, consumable, pass, pack |
| A dish that needs a technique the kitchen lacks | New behaviour, such as a dash, that needs code first |
| The head chef checking a new line before it goes up | ContentRules.validate running in CI on every pull request |
Think of a restaurant. The menu board lists dishes with prices, and the manager can add a dish or change a price with a marker. The kitchen knows techniques: grill, fry, bake. A new dish that is grilled goes straight on the board. A dish that needs a technique the kitchen does not have yet, say smoking, needs the kitchen to change first. And before a new line goes up, the head chef checks it: is there a price, do we have the ingredients?
Think of it as A restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line
Which of these changes needs only an item data edit at m15-scale?
Press 1 to 4 to choose, Enter to check.
Step 3 of 10
JSON files that Rojo turns into modules
Where does the data live? Rojo syncs any .json file that is not a model, project or meta file as a ModuleScript that returns the same structure as a table1. So src/shared/data/items.json:
{
"items": [
{ "id": "Speed", "kind": "upgrade", "price": 25, "currency": "Coins", "labelKey": "shop.speed" },
{ "id": "Shield", "kind": "consumable", "price": 40, "currency": "Coins", "labelKey": "shop.shield" },
{ "id": "CoinPack", "kind": "pack", "currency": "Robux", "productKey": "COIN_PACK", "labelKey": "shop.pack" },
{ "id": "SpeedPass", "kind": "pass", "currency": "Robux", "productKey": "SPEED_PASS", "labelKey": "shop.pass" }
]
}
becomes a ModuleScript at ReplicatedStorage.Shared.data.items, and require returns a table with an items array, on the server and the client alike. Robux items have no price: the Creator Hub owns Robux prices, and a second copy here would drift. They name the id key in Ids.luau instead. enemies.json holds the drone and crawler stats the same way. Both live in src/shared/data/ alongside rewards.json and zones.json. Only items and enemies wrap their rows inside a named object field.
With items.json synced by Rojo as above, what does this print in Studio?
local data = require(game.ReplicatedStorage.Shared.data.items)
print(#data.items, data.items[2].id, data.items[3].price)
Press 1 to 4 to choose, Enter to check.
Step 4 of 10
A validator that names every broken row
JSON accepts anything that parses. "price": -30, a typo in a label key, a kind nobody handles: all valid JSON. The validator is the head chef. It reads every row and reports every problem with the file, the row number, the id and the field, so a designer can fix them all in one go:
Validators can hold design rules too, not just shape. With WRENCH_DAMAGE = 34, the crawler's 68 health takes 2 hits and the drone's 100 takes 3. A rule such as "no enemy needs more than six wrench hits" stops a designer from shipping a 250-health drone that nobody can finish before the drill ends, and the rule lives next to the data instead of in someone's head.
With a wrench of 34 damage and a limit of six hits, what is the highest maxHealth the validator accepts?
Step 5 of 10
Run the rules on every pull request
A rule that only runs when someone remembers is not a rule. Keep the rules in one pure Luau module, src/shared/ContentRules.luau, with no Roblox calls, so three places can run the same code:
- CI, through a Lune script.
scripts/check-data.luaureads the JSON files with@lune/fs, decodes them withserde.decode("json", text)from@lune/serde, requires the rules with a relative path such asrequire("../src/shared/ContentRules"), prints each error and exits with code 1 when there are any23. Adatajob in.github/workflows/ci.ymlrunslune run scripts/check-data, next to the existingcheck-idsandcheck-challengesjobs. - The game, when
Configloads. If items or enemies are broken,Configraises an error and refuses to load, on every server, so a broken row that skipped CI cannot reach players. - A designer's plugin, which Tools for your team: plugins, CLIs and code generation builds. The plugin edits zones, so it runs the per-file schema described next, not ContentRules.
ContentRules holds the cross-file design rules for items and enemies, such as "the wrench kills this enemy in at most six hits". Its partner is src/shared/ContentSchema.luau, a per-file schema for every other data file (rewards.json, zones.json): each row needs a unique id, and each field has a type and limits. The same schema also writes the row types into GeneratedTypes.luau, so code that reads a row gets a real type for it.
Why keep the rules in one module with no Roblox calls, instead of writing the CI check in JavaScript like check-ids.mjs?
Press 1 to 4 to choose, Enter to check.
Step 6 of 10
Generate types from the data
Code still names items: ShopApp declares export type ShopItem = "Speed" | "Shield" | "CoinPack" | "SpeedPass" by hand. With items in data, that line is a copy that will drift. Generate it instead:
The Lune script writes that line into src/shared/GeneratedTypes.luau with a header saying the file is generated. Code that accepts ItemId can catch typos in scripts/typecheck.sh. ShopService.purchase takes unknown because it receives a remote argument, so it still checks the item id at runtime. Beacon Yard already generates files, in scripts/gen-assets.mjs, which builds account-bound models from templates and your ids; this follows the same pattern.
The generated file is committed. What should CI do about it?
Press 1 to 4 to choose, Enter to check.
Step 7 of 10
Data files or live configs?
Data files ship with a deploy. Some values must change without one: the Scrap Rush multiplier that FlagService reads from an Experience Config changes in running servers, no restart4. Use each for what it is good at:
- Data files: what exists. Items, enemies, labels, rewards and zones. Reviewed in a pull request, validated in CI, shipped with code that knows their kinds.
- Experience Configs: knobs on what exists. Event multipliers, a price for a weekend, a kill switch. Changed live, always clamped by limits in code, as
EVENT_MAX_MULTIPLIERclamps the event today.
Where content can live
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Luau tables in a ModuleScript | Config.luau today: constants and tables written in Luau. | Small games, programmer-tuned values. | Designers edit code; no schema beyond the type checker. |
| JSON modules via Rojo | Plain .json files Rojo turns into ModuleScripts. | Content that designers and scripts edit, validated in CI. | No comments in JSON; every rule lives in the validator. |
| TOML modules via Rojo | Rojo syncs .toml the same way; TOML allows comments. | Hand-edited config that benefits from notes. | Rojo turns TOML dates into strings; fewer tools than JSON. |
| Spreadsheet export | Designers work in a sheet; a script converts CSV to JSON, then the same validator runs. | Large tables tuned by non-programmers (economy, drops). | One more conversion step to keep in CI. |
| Experience Configs | Values set on the Creator Hub and read live by servers. | Live-ops knobs and kill switches. | Not for defining new content; always clamp in code. |
Marketing wants the Shield at 30 coins for this weekend only, starting tomorrow, without a new version. Where does that change go?
Press 1 to 4 to choose, Enter to check.
Step 8 of 10
Build along: items and enemies as data
You build this in your own copy of the finished game. First pass the level 3 challenge below, then copy challenges/work/content_rules.luau to src/shared/ContentRules.luau.
The data job fails a pull request and names the row and field to fix.
src/shared/data/items.jsonsrc/shared/data/enemies.jsonsrc/shared/data/rewards.jsonsrc/shared/data/zones.jsonsrc/shared/Content.luausrc/shared/Config.luausrc/shared/ContentRules.luausrc/shared/ContentSchema.luausrc/shared/GeneratedTypes.luauscripts/check-data.luausrc/server/ShopService.luauunit/specs/ContentSchema.spec.luau.github/workflows/ci.yml
Place the four JSON files in
src/shared/data/. Wrapitemsandenemiesin objects with named arrays. Read the rows throughContent;Configreads item prices and enemy stats through it, and keeps numbers likeWRENCH_DAMAGE.You should see ReplicatedStorage.Shared.data contains items, enemies, rewards and zones after a Rojo sync.
Look up the id with
Content.findItem. Dispatch viaHANDLERSforupgrade,consumable,passandpack. Keep the per-id coin effects and the hand-written shop buttons.You should see ShopService.purchase dispatches by the row kind.
Run
lune run scripts/check-data. The script checks item and enemy rows withContentRules, using keys fromsrc/locale/Strings.csvand wrench damage read from the text ofConfig.luau. It also runsContentSchema.validateAll. Use--writeto regenerateGeneratedTypes.luau.You should see The check reports four valid files and exits 0. A negative coin price fails the check.
Use the
datajob in.github/workflows/ci.ymlandunit/specs/ContentSchema.spec.luauas references. At this tag, the cross-row case checks the Yard boundary.You should see The data job runs the same check. The zone spec rejects a box outside the Yard.
Step 9 of 10
Where the menu picture breaks
Where does it break?“A restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line” is a good picture of content as data, behaviour as code. Where does it stop being true?
It breaks here. A chef can ask what a strange line means; code cannot, so every assumption it makes about the data has to be a validator rule. And a menu board is a few dozen lines read at a glance, while game data is hundreds of rows across files that refer to each other, which only the validator and generated types check.
The true model. Data lists the content and code handles each kind of content; a pure Luau validator checks shape, links and design rules everywhere the data can change, types generated from the data check the links from code, and Experience Configs tune shipped content live within limits.
There is a second break. A menu board has a few dozen lines a chef can read at a glance. Game data grows to hundreds of rows across many files that refer to each other: an item's label key must exist in the translations, a zone box must stay inside the Yard. The validator is what checks those links, and generated types are what check the links from code.
Step 10 of 10
Challenges and recap
This validator never notices a duplicate id, so the second Drone row silently replaces the first wherever code looks rows up by id. Fix it so a repeated id is an error.
Level 1, Apprentice
Challenge
Fix validate in the dup-fix cell.
- Start from
- The game at milestone m14 (download)
- Check it here
- Run the code cell; the challenge completes when it passes. No Studio needed.
Done means
- validate remembers each id it has seen
- A repeated id gives one error naming its row and the id field
- All four assertions in dup-fix pass
Put a designer's Repair Kit change in order once the build-along is done.
- CI's data job runs ContentRules on every row and checks the generated file is current
- Run lune run scripts/check-data --write to regenerate GeneratedTypes.luau
- Add a consumable row and a shop.repair line in Strings.csv
- Open a pull request
- After review and merge, add the kit's button and effect, then the deploy ships it
Level 2, Builder
Challenge
Prove the pipeline with a real item. There is no Luau test for this one: the proof is the failed and then passing pull request, and the kit in the shop.
- Start from
- The game at milestone m14 (download)
Done means
- The build-along is done in your copy: items and enemies in JSON, ContentRules, check-data and the CI job
- A Repair Kit row for 30 coins validates after you add its label and regenerate GeneratedTypes.luau
- A test pull request with the price set to -30 fails the data job with a message naming RepairKit and price
- The fixed pull request passes, and in Play the shop sells the kit
Meet the criteria above, then record your own result. No test grades this check.
Level 3, Professional
Challenge
Write validate, hitsToKill and itemIdType in challenges/work/content_rules.luau. The written solution is challenges/solutions/data-driven-content.md. In Play, run game.ServerScriptService.RunGameTests:Invoke("data-driven-content", "data-rules") and paste the pass code here.
- Start from
- The game at milestone m14 (download)
- Grade it
- In Studio, press Play, then run
game.ServerScriptService.RunGameTests:Invoke("data-driven-content", "data-rules")in the server command bar. Copy the pass code from Output.
Done means
- The real yard data passes with no errors
- Each of fifteen broken rows gives exactly one error naming the row's id and the field
- Several broken fields give one error each
- hitsToKill rounds up, and an enemy that takes exactly six hits is allowed
- itemIdType returns the export type line with quoted, sorted ids
- challenges/data-driven-content.luau prints TEST PASS for every check
Retiring the analogy
You no longer need “a restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line”. Data lists the content and code handles each kind of content; a pure Luau validator checks shape, links and design rules everywhere the data can change, types generated from the data check the links from code, and Experience Configs tune shipped content live within limits.
Recap
- At m14-ship one shop item touches seven files, all code but one, because items are known by name in code.
- Data lists the things; code handles each kind. A new row of a known kind needs no code in the shop service; buttons and effects are still hand-written at m15-scale.
- Rojo syncs a .json file as a ModuleScript that returns the table; missing fields read as nil.
- One pure ContentRules module checks items and enemies, reports every broken row by file, row, id and field, and runs in CI through Lune and when Config loads. ContentSchema checks every other file, and the zone plugin runs it too.
- Generate the ItemId type from the data, commit it, and have CI fail when it is stale.
- Data files define what exists and ship with a deploy; Experience Configs tune it live, always clamped in code.
Content as data, behaviour as code is a restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line, until a chef can ask what a strange line means; code cannot, so every assumption it makes about the data has to be a validator rule. And a menu board is a few dozen lines read at a glance, while game data is hundreds of rows across files that refer to each other, which only the validator and generated types check.
Queued for review
- Which of these changes needs only an item data edit at m15-scale?
- With items.json synced by Rojo as above, what does this print in Studio?
- With a wrench of 34 damage and a limit of six hits, what is the highest maxHealth the validator accepts?
- Why keep the rules in one module with no Roblox calls, instead of writing the CI check in JavaScript like check-ids.mjs?
- Marketing wants the Shield at 30 coins for this weekend only, starting tomorrow, without a new version. Where does that change go?