Datastore
Datastore (not to be confused with the Datastore data type) is a service used for storing data between place sessions.
Limits
Rate Limit: up to (30 + (10 * [amount of players])) requests per minute (for example; a server with 5 players would have a limit of 80 requests/min)
Datastore Size: up to 65,535 bytes
Key Length: up to 32 characters
There is a limit placed on the Datastore functions per server instance. Requests that exceed this limit will be canceled and return an error. Read and write functions both have their own rate limit of (30 + (10 * [amount of players])) requests per minute. This limit is reset every minute.
You can create as many datastores as you want, however each datastore is limited to 65,535 bytes and it's key cannot be longer than 32 characters. Creating a datastore will also count towards the rate limit.
If you are testing your place locally through Polytoria Creator, no requests will be made to the server and your data will not be saved after the session ends. You will need to upload your place to the website to test the requests.
Summary
Properties
Loading:boolRead Only
Methods
GetDatastore:DatastoreGet:callbackRemove:callbackSet:callback
Events
Loaded:void
Properties
Loading
Datastore.Loading: bool
Returns true or false depending on if the Datastore object is loaded.
Example
local ds = Datastore:GetDatastore("Player_" .. player.UserID)
while ds.Loading do
wait()
end
Methods
GetDatastore
Datastore:GetDatastore(datastoreName: string): Datastore
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
datastoreName | string | - |
Attempts to get a Datastore object from the Datastore service.
Example
local ds = Datastore:GetDatastore("Player_" .. player.UserID)
Make sure to wait until the Datastore object is loaded by waiting until the .Loaded event on the Datastore object is fired.
Get
Datastore:Get(key: string, callback: function): callback
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | - | |
callback | function | - |
Attempts to get the value of a key from a Datastore.
Example
-- Attempts to get the value of "Coins"
ds:Get("Coins", function(value, success, error)
if not success then
print(error)
else
print(player.Name .. " has " .. value .. " coins.")
end
end)
Remove
Datastore:Remove(key: string, callback: function): callback
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | - | |
callback | function | - |
Attempts to remove a key from a Datastore.
Example
-- Attempts to remove the key "Coins"
ds:Remove("Coins", function(success, error)
if not success then
print(error)
else
print(player.Name .. "'s coins have been removed!")
end
end)
Set
Datastore:Set(key: string, value: any, callback: function): callback
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | - | |
value | any | - | |
callback | function | - |
Attempts to set the value of a key in a Datastore
Example
-- Attempts to set the value of "Coins" to 100
ds:Set("Coins", 100, function(success, error)
if not success then
print(error)
else
print(player.Name .. "'s coins have been set to 100!")
end
end)
Properties
Events
Loaded
Datastore.Loaded()
Fires when the Datastore object loads.
Example
local ds = Datastore:GetDatastore("Player_" .. player.UserID)
ds.Loaded:Connect(function ()
ds:Set("Coins", 100)
end)