Is there a way to check if a place has been published using code?

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?

1 Like

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.

1 Like

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.

3 Likes

I guess using pcall is my best option then. Thanks for the help guys!

2 Likes

: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:

4 Likes

Is there a way so if it is not the right place id