Show raw api
{
"functions": [
{
"name": "new",
"desc": "Constructs a new DataStore. See [DataStoreStage] for more API.\n\n```lua\nlocal dataStore = serviceBag:GetService(PlayerDataStoreService):PromiseDataStore(player):Yield()\n```",
"params": [
{
"name": "robloxDataStore",
"desc": "",
"lua_type": "DataStore"
},
{
"name": "key",
"desc": "",
"lua_type": "string"
}
],
"returns": [
{
"desc": "",
"lua_type": "DataStore"
}
],
"function_type": "static",
"source": {
"line": 116,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "SetDoDebugWriting",
"desc": "Set to true to debug writing this data store",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
},
{
"name": "debugWriting",
"desc": "",
"lua_type": "boolean"
}
],
"returns": [],
"function_type": "static",
"source": {
"line": 151,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "GetFullPath",
"desc": "Returns the full path for the datastore",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "string"
}
],
"function_type": "static",
"source": {
"line": 161,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "SetAutoSaveTimeSeconds",
"desc": "How frequent the data store will autosave (or sync) to the cloud. If set to nil then the datastore\nwill not do any syncing.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
},
{
"name": "autoSaveTimeSeconds",
"desc": "",
"lua_type": "number?"
}
],
"returns": [],
"function_type": "static",
"source": {
"line": 171,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "SetSyncOnSave",
"desc": "How frequent the data store will autosave (or sync) to the cloud",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
},
{
"name": "syncEnabled",
"desc": "",
"lua_type": "boolean"
}
],
"returns": [],
"function_type": "static",
"source": {
"line": 182,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "DidLoadFail",
"desc": "Returns whether the datastore failed.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "static",
"source": {
"line": 192,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "PromiseLoadSuccessful",
"desc": "Returns whether the datastore has loaded successfully.\\",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "Promise<boolean>"
}
],
"function_type": "static",
"source": {
"line": 209,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "Save",
"desc": "Saves all stored data.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "Promise"
}
],
"function_type": "static",
"source": {
"line": 221,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "Sync",
"desc": "Same as saving the data but it also loads fresh data from the datastore, which may consume\nadditional data-store query calls.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "Promise"
}
],
"function_type": "static",
"source": {
"line": 231,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "SetUserIdList",
"desc": "Sets the user id list associated with this datastore. Can be useful for GDPR compliance.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
},
{
"name": "userIdList",
"desc": "",
"lua_type": "{ number }?"
}
],
"returns": [],
"function_type": "static",
"source": {
"line": 240,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "GetUserIdList",
"desc": "Returns a list of user ids or nil",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "{ number }?"
}
],
"function_type": "static",
"source": {
"line": 252,
"path": "src/datastore/src/Server/DataStore.lua"
}
},
{
"name": "PromiseViewUpToDate",
"desc": "Overridden helper method for data store stage below.",
"params": [
{
"name": "self",
"desc": "",
"lua_type": "DataStore"
}
],
"returns": [
{
"desc": "",
"lua_type": "Promise"
}
],
"function_type": "static",
"source": {
"line": 261,
"path": "src/datastore/src/Server/DataStore.lua"
}
}
],
"properties": [
{
"name": "Saving",
"desc": "Prop that fires when saving. Promise will resolve once saving is complete.",
"lua_type": "Signal<Promise>",
"source": {
"line": 139,
"path": "src/datastore/src/Server/DataStore.lua"
}
}
],
"types": [],
"name": "DataStore",
"desc": "Wraps the datastore object to provide async cached loading and saving. See [DataStoreStage] for more API.\n\nHas the following features\n* Automatic saving every 5 minutes\n* Jitter (doesn't save all at the same time)\n* De-duplication (only updates data it needs)\n* Battle tested across multiple top games.\n\n```lua\nlocal playerMoneyValue = Instance.new(\"IntValue\")\nplayerMoneyValue.Value = 0\n\nlocal dataStore = DataStore.new(DataStoreService:GetDataStore(\"test\"), \"test-store\")\ndataStore:Load(\"money\", 0):Then(function(money)\n\tplayerMoneyValue.Value = money\n\tdataStore:StoreOnValueChange(\"money\", playerMoneyValue)\nend):Catch(function()\n\t-- TODO: Notify player\nend)\n```\n\nTo use a datastore for a player, it's recommended you use the [PlayerDataStoreService]. This looks\nsomething like this. See [ServiceBag] for more information on service initialization.\n\n```lua\nlocal serviceBag = ServiceBag.new()\nlocal playerDataStoreService = serviceBag:GetService(require(\"PlayerDataStoreService\"))\n\nserviceBag:Init()\nserviceBag:Start()\n\nlocal topMaid = Maid.new()\n\nlocal function handlePlayer(player: Player)\n\tlocal maid = Maid.new()\n\n\tlocal playerMoneyValue = Instance.new(\"IntValue\")\n\tplayerMoneyValue.Name = \"Money\"\n\tplayerMoneyValue.Value = 0\n\tplayerMoneyValue.Parent = player\n\n\tmaid:GivePromise(playerDataStoreService:PromiseDataStore(player)):Then(function(dataStore)\n\t\tmaid:GivePromise(dataStore:Load(\"money\", 0))\n\t\t\t:Then(function(money)\n\t\t\t\tplayerMoneyValue.Value = money\n\t\t\t\tmaid:GiveTask(dataStore:StoreOnValueChange(\"money\", playerMoneyValue))\n\t\t\tend)\n\tend)\n\n\ttopMaid[player] = maid\nend\nPlayers.PlayerAdded:Connect(handlePlayer)\nPlayers.PlayerRemoving:Connect(function(player)\n\ttopMaid[player] = nil\nend)\nfor _, player in Players:GetPlayers() do\n\ttask.spawn(handlePlayer, player)\nend\n```",
"realm": [
"Server"
],
"source": {
"line": 66,
"path": "src/datastore/src/Server/DataStore.lua"
}
}