Document
A piece of saved data, such as a player's profile, which you get from data.profile or DocumentCollection:open and change in place.
Reads the value at a path in the Document, or the whole value if you give no path.
example
local gold = profile:get("coins")
Use it forreading a player's saved tokens so you can show them in the shop.
pathoptionalDots through fields, list positions from 1. Nil or empty gives the whole value.
Changes the value at a path to a new value, which is checked against the schema.
Document:set(path: string, value: any) -> ()
example
profile:set("coins", 100)
Use it forsaving the checkpoint a player just reached so they can start there next time.
pathDots through fields, list positions from 1.
valueThe new value.
Document:increment
method#Adds an amount to a number, 1 if you don't give one, and gives back the new number.
Document:increment(path: string, amount: number?) -> number
example
profile:increment("coins", 5)
Use it foradding tokens to a player's total each time they pick one up.
pathThe path of a number.
amountoptionalHow much to add. 1 by default.
Adds an item to the end of a list in the Document.
Document:push(path: string, value: any) -> ()
example
profile:push("items", "sword")
Use it foradding a new sword to a player's saved inventory when they buy or find one.
pathThe path of a list.
valueThe item to add at the end.
Removes the value at a path from the Document.
example
profile:remove("items.1")
Use it fortaking an item out of a player's inventory once it has been used up.
pathDots through fields, list positions from 1.
Changes the whole value of the Document at once, instead of one path at a time.
example
profile:replace({ coins = 0, items = {} })
Use it forresetting all of a player's progress when they choose to start a new game.
valueThe new whole value.
Gives the value at a path to a function you write, and saves whatever it returns.
Document:update(path: string, transform: (any) -> any) -> any
example
profile:update("coins", function(value) return value + 1 end)
Use it forchanging a guild's member count safely, even when two servers edit it at the same time.
pathDots through fields, list positions from 1.
transformGets the value and returns the new one. It can run more than once.
Saves a player's Profile sooner, instead of waiting for the next save every 60 seconds.
Use it forsaving right away after a player buys something important, rather than up to a minute later.