Im making a File Selection GUI and i want to prevent filling up the queue.
Is it possible to see if there is any data in the DataStore with LocalScripts?
Also, some of the values are set to default values (Health = 20)
This post is closed because i found a way to do this by myself. The solution is not so elegant, but hey! It works just fine.
Datastores can only be accessed by normal scripts. So in terms: no. You will not be able to directly see if a datastore has data via a LocalScript. What you’ll instead want to do is utilize RemoteFunctions to invoke a function on the server that returns the data that is needed back to the LocalScript.
Will the event return nil if there is no saved data?
Yes, it can very well return nil if you don’t provide extra checks into making sure that the data retrieved by GetAsync() isn’t nil. This is provided as long as you are returning the value retrieved by it to the client. Which if you don’t, as the function isn’t returning any data, will return nil, every-time it is called upon.
Briefing About Saving Files
Perhaps when the server loads, fire a RemoteFunction to the server to obtain a table with the tables of data. If the RemoteFunction returns nil, you’ll set the save as empty. When the save is iterated or created, use a template of data for the player’s save.
Remember to not save too often, you’ll bump into the data store errors if you run SetAsync or similar too often. A manual saving with an automatic saving that has a long time interval will probably solve it. Error the player or simply disable the button until they can save again.
However, since bandwidth limitations exist, it may be slightly difficult. Instead, pass the arguments with the necessary data needed. Maybe fire the remote per file will solve it.
Also thanks for the idea of using different save files, I’ll write some module to my awesome scripting suite that I can use for game creation in less time.
How would the table get data from the datastore?
As previously mentioned, you can save tables into the data store. Call GetAsync from it and it will return a table, depending on the key and scope from the data store.
I write the templates like this or similar first, then apply to the player’s data when possible.
local templateData = {
Experience = 0;
Cash = 0;
ScopedData = {
"Hello";
"Friend";
}
}
print(templateData["ScopedData"][1] .. " ".. templateData["ScopedData"][2])
Of course, if nothing is saved, it’ll return nil. Therefore, you will pass nil value to the player which then finds the save file empty, thus making it an empty save file ready to be written.