Document
Functions
read
Document:read() → anyReturns the document's data.
write
Document:write(data: any) → ()Updates the document's cached data. This method doesn't save the data to the DataStore; it only modifies the document's in-memory data.
This method should be used when performing immutable updates to the document's data. For mutable updates, the data can be directly modified:
local data = document:read()
data.coins += 100
warning
Throws an error if the document was closed or if the data is invalid.
addUserId
Document:addUserId(userId: number) → ()
Adds a user id to the document's DataStoreKeyInfo:GetUserIds(). The change won't apply until the document is
saved or closed.
If the user id is already associated with the document the method won't do anything.
removeUserId
Document:removeUserId(userId: number) → ()
Removes a user id from the document's DataStoreKeyInfo:GetUserIds(). The change won't apply until the document is
saved or closed.
If the user id is not associated with the document the method won't do anything.
keyInfo
Returns the last updated DataStoreKeyInfo returned from loading, saving, or closing the document.
save
Document:save() → Promise<()>Saves the document's data. If the save is throttled and you call it multiple times, it will save only once with the latest data.
Documents are saved automatically. This method is used mainly to handle developer product purchases (see the example) or other situations requiring immediate saving.
warning
Throws an error if the document was closed.
warning
If the beforeSave callback yields or errors, the returned promise will reject and the data will not be saved.
close
Document:close() → Promise<()>Saves the document and removes the session lock. The document is unusable after calling. If a save is currently in progress it will close the document instead.
If called again, it will return the promise from the original call.
warning
If the beforeSave or beforeClose callbacks yield or error, the returned promise will reject and the data will not be saved.
beforeSave
Document:beforeSave(callback: () → ()) → ()
Sets a callback that is run inside document:save and document:close before it saves. The document can be read and written to in the
callback.
The callback will run before the beforeClose callback inside of document:close.
warning
Throws an error if it was called previously.
beforeClose
Document:beforeClose(callback: () → ()) → ()
Sets a callback that is run inside document:close before it saves. The document can be read and written to in the
callback.
warning
Throws an error if it was called previously.