Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.

← Back to journey

Choose what should survive a session

v2 · Activity 1 of 0 · persistent-state · temporary-state · schema · 28 min Requires Roblox Studio

Chapter outline
Loading draft…
Mini-mission

A durable record might contain completed objective IDs and a preference. A current tween, open panel, connection, or character reference belongs to the current session.

Define a versioned data shape using plain serializable values. This lab builds a record; it does not write to a datastore yet.

Your task

Create SaveShape.build(state) that returns version=1, a copied completed sequence, and soundEnabled preserving false. Omit panelOpen, activeTween and character. Missing sound defaults to false.

Interface: Complete the documented Studio hierarchy and self-check the behavior outside the browser.

InputExpected
Syntax in this activity

New syntax: persistent-state, temporary-state, schema

Earlier ideas used here
  • server-state
  • authority
  • nil
  • guards
Self-check rubric
  • The record has version, completed and soundEnabled only.
  • False remains false and absent sound defaults to false.
  • Changing the original completed list does not change the built snapshot.

Your explanation is a self-check. Exact wording is not automatically graded.

Self-checked Studio exercise. A saved checklist records your own review; no uploaded place file or screenshot is executed here.

Build this hierarchy

ServerScriptService/SaveShape (ModuleScript)
ServerScriptService/TestSaveShape (Script, RunContext=Server)
  1. Create the two files in an isolated practice place.
  2. No API-services grant or datastore connection is needed for these local schema tests.
ServerScriptService/SaveShape.luau

Module selects minimal durable fields.

local SaveShape = {}
function SaveShape.build(state)
    local soundEnabled = false
    if type(state.soundEnabled) == "boolean" then soundEnabled = state.soundEnabled end
    return { version = 1, completed = table.clone(state.completed or {}), soundEnabled = soundEnabled }
end
return SaveShape
ServerScriptService/TestSaveShape.server.luau

Controlled local assertions test the schema without any datastore access.

local SaveShape = require(script.Parent.SaveShape)
local state = { completed = {"lamp"}, soundEnabled = false, panelOpen = true }
local save = SaveShape.build(state)
assert(save.version == 1 and save.soundEnabled == false)
assert(save.panelOpen == nil and save.completed ~= state.completed)
print("Save shape checks passed")

Expected output

  • Server Output prints Save shape checks passed.

Studio assessment checklist

Multiplayer tests

  1. Run a local server and at least one client; compare server and client context where the activity uses both.
Troubleshooting and production considerations

A shallow clone is sufficient only because completed contains string IDs here.

Do not put engine Instances or connection objects into the save record.

This is a bounded learning lab. It has not been executed in an approved Roblox Studio environment by this website.

A checked checklist records your own review, not automated project competence or a community verification.

Your goal

Create SaveShape.build(state) that returns version=1, a copied completed sequence, and soundEnabled preserving false. Omit panelOpen, activeTween and character. Missing sound defaults to false.

Reset starter

Replace this code with the starter? Download your draft to keep a copy.

Code

Studio source file
Luau keyword highlighting · Ctrl/⌘ + Enter: Run · Esc: leave editor

Edit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.

Your output will appear here.

Ready