Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What are datastores?

Asked by 8 years ago

I wanted to know what a data store was, I understand many games use em to save progress but, how do they save it? Do they use strings? Numbers, How exactly do data store's work, I also wanted to know, can you build datastores on one place and connect to it from another to load the players save?

1 answer

Log in to vote
3
Answered by 8 years ago

DataStores

DataStores are a way to save information between servers. They are a very powerful system which allows persistence of data ranging from information about players, to information about whole servers. The application of them is down to what you need to save.


What can they save?

Tables

Tables can be saved in DataStores, however they must contain other primative datatypes which can be saved in a DataStore. If a table has both an array part and a dictionary part, one of the parts will be lost (Likely the array part) because the table is saved to JSON.

Strings

You can save strings. There's a small limitation on strings which you won't hit, which is that they can't save certain characters due to how the C side of the code handles the strings. It's unfortunate, but you don't need to worry about it.

Numbers

Numbers are probably simplified to floats on the C side rather than being represented wholly as doubles. But that also doesn't matter to you, so feel free to save as many numbers as you want.

Booleans

If it's true or false, you can save it. Technically you can also save nil, but why would you bother?


What's the limitations?

Request Limit

The limit for requests on DataStores is 60+10*numPlayers requests per minute. You might think that's really small, but don't worry because it's actually massive - If you're doing everything right, you shouldn't need to worry about accidentally hitting the limit. There's also individual limits for the OnUpdate events (30+5*numPlayers per minute) and the GetSorted method (5+2*numPlayers per minute) so be careful with those.

Any requests exceeding the limit will be throttled instead of simply being dropped, but it could cause long waiting times if you hit the limit. You have been warned.

Data Limit

Your total limit for each individual value is about the same amount as a string with 2^18 characters. If you're not sure, that's a lot, but you can check how much data you're saving in a table by JSONEncoding it and checking the length of the string.

stringtab = HttpService:JSONEncode(savetab);
if #stringtab > 2^18 then
    warn "Too large to save. Good luck."
end

Instances and Other Userdata

Userdata can not be saved in a DataStore, because there's no standard to serialize them in JSON. As a result, you'll have to look for your own serialization methods if you need to store things like position data or colour preferences.


Where can I use them?

DataStores can be used from anywhere within the same universe. This means that they can be used across servers, and even across places, so long as they're in the same game (universe). Happy saving.

Ad

Answer this question