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

How to test if a datastore exists?

Asked by 6 years ago

I'm making a (weird) save, please don't say that I should make another kind of save because I want to do it this way xD. so the question, how do I detect if a datastore exists? I have no script pieces because that's the first thing I need to know so I have to start with that, I don't need a prebuilt script, just a wiki link or some explanation...

1 answer

Log in to vote
0
Answered by 6 years ago

For all intents and purposes, as soon as you get a reference to a DataStore

local myDataStore= game:GetService('DataStoreService'):GetDataStore('MyData')

you can think of it as "existing".

The only thing you can really do is check is whether or not any data has previously been written to it.

local value = myDataStore:GetAsync('key')
if value == nil then
    print("A value does not exist in 'myDataStore' for key 'key'")
end
Ad

Answer this question