Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

modules.runtime_data

The high-level, persistent + replicated data layer for a world. Wraps the low-level __world_data.* FFI primitives (the generic engine capability) into an ergonomic per-world + per-player system.

Use it for substantial state that must survive restarts and replicate to every client: progression, saved builds, per-player records, large structured data. NOT the transient multiplayer relay — small, fast-changing throwaway state belongs there instead.

Generic + opaque: it never interprets a key or a value. Values are any JSON-serializable Luau value; what you store and in what shape is yours.

-- one shared world store
runtime_data.world.set("phase", "night")
local phase = runtime_data.world.get("phase")

-- a player's store, keyed by an explicit user id (read any player,
-- write only your own — server-enforced)
local me = runtime_data.player(runtime_data.localId())
me.set("inventory/weapons/primary/ammo", 30)   -- partial deep write
local ammo = me.get("inventory/weapons/primary/ammo")
local inv  = me.getTree("inventory")            -- nested table

-- per-player data is tied to the player object
world.connectedUsers.localUser.data.set("level", 12)
layers.active.players.localPlayer.data.get("level")

Keys are slash-paths; every path is an independent, independently replicating row — a deep write touches only that leaf. Reads are synchronous (local replica, with your own writes laid over it, so a read straight after a write returns what you wrote); writes return a promise id you can task.await(...) to confirm, and writes to one path apply in the order they were made. Subscribe to live changes with onChange / onPlayerChange (event-driven — no per-frame polling).