Codectionary / Developer documentation / Luau

DataStore setup and safe Studio testing

DataStoreService persists data across sessions and is accessed by server scripts. Studio API access can reach real experience data. Use a separate test experience and test store names before enabling access; these examples are learning exercises, not a complete production persistence framework.

Syntax

local store = game:GetService("DataStoreService"):GetDataStore("LessonProgress_TEST_v1")

Examples

Choose an explicit test namespace

Script in ServerScriptService of a separate published test experience. Enable Studio API access only for that test experience. This obtains a store handle; it does not read or write data yet.

local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("LessonProgress_TEST_v1")
local function playerKey(userId: number): string
    return "player:" .. tostring(userId)
end
print("Test key:", playerKey(12345))

Inspect a request budget

Separate server Script in the test experience. A budget value is a point-in-time hint, not a reservation or a promise that the next request succeeds. All requests still need protected calls and a failure path.

local DataStoreService = game:GetService("DataStoreService")
local budget = DataStoreService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync)
print("Current read budget:", budget)
if budget < 1 then
    warn("Defer non-essential reads instead of starting a burst")
end

Best practices

  • Do not test against production player keys; a different key alone is weaker isolation than a separate experience.
  • Use stable UserId-based keys rather than names.
  • Plan for throttling, unavailable services, schema changes and failed saves before relying on persistence.

At a glance

Purpose
Typed scripting and Roblox development
File extension
.luau
Runs in
Luau host; Roblox engine examples require Roblox Studio
Usually used with
Roblox APIs and Studio

Specifications & further reading

Related Luau documentation