When you try to access data stores in a place that has been opened from your desktop and has not been published yet, it throws a “You must publish this place to the web to access DataStore” error. Is there a way I can have my code check if the place has been published before it tries to access data stores?
You could check if game.PlaceId ~= 0
Then again, you would also have to go to the Game settings and turn on “Allow Studio access to API services” to allow DataStore access from studio. To check that, you would just have to wrap a pcall
around a DataStoreService:GetDataStore()
and check for the signature error.
They will be 0 instead of nil for local files. BEWARE though: When creating a place through File>New/Ctrl+N/one of the template places, fields like PlaceId/CreatorId will default to one of the templates owned by the Templates user until you save and reload the file. AFAIK this is the only way you can tell if the place is not published, so you will either need to hardcode CreatorId==998796 (Templates account) as local files, or save+reload for affected places.
I guess using pcall is my best option then. Thanks for the help guys!
:GetDataStore(…) will work fine in a non-published file server-side. It will only error once you actually make a request.
@AxonMega Review the code here for your convenience:
https://github.com/buildthomas/MockDataStoreService/blob/master/src/DataStoreService.lua
Is there a way so if it is not the right place id