Skip to main content

DataController

This item only works when running on the client. Client

Handles data replication coming from the server.

Functions

GetDataReplica

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
DataController:GetDataReplica() → Replica

Returns the Replica object that contains player data. Yields until the replica is available.

GetData

DataController:GetData() → {[string]any}

Returns the top-level player data table containing both session and profile data.

WARNING

This table is read-only. Do not attempt to write to it directly.

GetValue

DataController:GetValue(
keyPathstring | {string}--

The dot-separated path or array of keys

) → any?

Returns the value at the specified path in the player data table. Paths can be dot-separated strings or string arrays.

DataController:GetValue("SomeKey.SomeOtherKey")
-- OR
DataController:GetValue({"SomeKey", "SomeOtherKey"})

Observe

DataController:Observe(
pathstring,--

The dot-separated path to observe

callbackfunction--

Called with (newValue, oldValue) immediately and on every change

) → RBXScriptConnection

Immediately invokes callback with the current value at path, then listens for changes and invokes it again on every subsequent update.

DataController:Observe("SomeKey.SomeOtherKey", function(newValue, oldValue)
	print("Value changed from", oldValue, "to", newValue)
end)

SetValueCallback

DataController:SetValueCallback(
pathstring | {string},--

The path to listen to

callbackfunction,--

Called with (newValue, oldValue) on change

runImmediatelyboolean?--

Whether to invoke the callback immediately with the current value

) → RBXScriptConnection

Sets a callback to be run when the value at path changes. If runImmediately is true, behaves identically to Observe and invokes the callback with the current value right away.

Show raw api
{
    "functions": [
        {
            "name": "GetDataReplica",
            "desc": "Returns the `Replica` object that contains player data. Yields until the\nreplica is available.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Replica"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 68,
                "path": "src/client/core/tasks/DataController.luau"
            }
        },
        {
            "name": "GetData",
            "desc": "Returns the top-level player data table containing both session and profile\ndata.\n\n:::warning\nThis table is read-only. Do not attempt to write to it directly.\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ [string]: any }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 93,
                "path": "src/client/core/tasks/DataController.luau"
            }
        },
        {
            "name": "GetValue",
            "desc": "Returns the value at the specified path in the player data table. Paths can\nbe dot-separated strings or string arrays.\n\n```lua\nDataController:GetValue(\"SomeKey.SomeOtherKey\")\n-- OR\nDataController:GetValue({\"SomeKey\", \"SomeOtherKey\"})\n```",
            "params": [
                {
                    "name": "keyPath",
                    "desc": "The dot-separated path or array of keys",
                    "lua_type": "string | {string}"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 110,
                "path": "src/client/core/tasks/DataController.luau"
            }
        },
        {
            "name": "Observe",
            "desc": "Immediately invokes `callback` with the current value at `path`, then\nlistens for changes and invokes it again on every subsequent update.\n\n```lua\nDataController:Observe(\"SomeKey.SomeOtherKey\", function(newValue, oldValue)\n\tprint(\"Value changed from\", oldValue, \"to\", newValue)\nend)\n```",
            "params": [
                {
                    "name": "path",
                    "desc": "The dot-separated path to observe",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "Called with (newValue, oldValue) immediately and on every change",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "RBXScriptConnection"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 143,
                "path": "src/client/core/tasks/DataController.luau"
            }
        },
        {
            "name": "SetValueCallback",
            "desc": "Sets a callback to be run when the value at `path` changes. If\n`runImmediately` is true, behaves identically to `Observe` and invokes the\ncallback with the current value right away.",
            "params": [
                {
                    "name": "path",
                    "desc": "The path to listen to",
                    "lua_type": "string | {string}"
                },
                {
                    "name": "callback",
                    "desc": "Called with (newValue, oldValue) on change",
                    "lua_type": "function"
                },
                {
                    "name": "runImmediately",
                    "desc": "Whether to invoke the callback immediately with the current value",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "RBXScriptConnection"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 159,
                "path": "src/client/core/tasks/DataController.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "DataController",
    "desc": "Handles data replication coming from the server.",
    "realm": [
        "Client"
    ],
    "source": {
        "line": 15,
        "path": "src/client/core/tasks/DataController.luau"
    }
}