Plugin Datastores

I am making a plugin named qCopy and it uses DataStoreService to save things. It is all on a server script however when it loads the datastore, it says it cannot be accessed from the client. Is there any work-arounds or a different way to save data?

1 Like

You should use plugin:SetSetting and plugin:GetSetting to save and load plugin data. DataStore access has to be manually enabled for use in Studio.

In play testing, the plugin runs one instance on the client and one on the server. You cannot access DataStores on the client, so will error on the client side. Switch to server in play modes, and it’ll run fine.

You can use RunService:IsServer to check if a plugin is running on client or server to prevent running on the client in play modes:

6 Likes

That is for if they have used the plugin before. How could I save the data though? The data is in a table like so:

local example = {Collections = {Number = number.Value}
1 Like

A really basic way would be like this:

local example = plugin:GetSetting("ExampleData") or {
    Collections = {
        Number = number.Value
    }
}

That’s basically saying “If ExampleData is saved, use it. If it’s nil, use this table instead.”

Ideally, you’d merge the saved data into the default data table, as you’d be able to add data later in an update without disrupting previously saved data, but this is fine with basic usage.

Then to save, just use the following:

plugin:SetSetting("ExampleData", example)
8 Likes

I’ll try this out! I will get back if it works.

2 Likes

Those are terribly unreliable, the Plugin API overall is half broken so be careful and test well.

Use IsRunning instead.


DataStore isn’t accessible in other Game Universes, it seems like what you are doing would rely on the data being persistent everywhere for that User, thus making DataStore a terrible solution, I should note that this also doesn’t work well for multiple devices because Get/Set Setting is iirc Local.

1 Like

Good catch! That’s what I meant :sweat_smile:

:IsServer will return true when outside of play testing modes too. Use both :IsRunning and :IsServer together to prevent the plugin running on the client in play mode.

As for the plugin APIs, I can’t say I’ve ever had an issue with data persistence.

After testing your method, it all seems to save! Thank you guys for all your help!

I recently noticed if I close out of studio, the plugin data is lost. Is there a way I can save the data from each studio session or no?

The plugin:SetSetting method should save the data to your PC in a JSON file.

You can always double check the file updates correctly, by opening the JSON file. It’s something like %localappdata%/Roblox/Plugins/<PluginID>/settings.json (PluginID is 0 if saved as a local plugin; you can click “Open Plugins Folder” in the Studio Plugins tab and just go up to the Roblox LocalAppData folder for more convenient access).

If you find that the file isn’t modified by Studio when you call SetSetting, file a bug report.

As a workaround, if you only need settings saved on a per-game basis, you can create a Folder in ServerStorage for your plugin, and saved values using ValueBases (StringValue, NumberValue, etc.).

1 Like

Ok thanks. It saves sometimes, but I have worked around it by using caches. Thanks again for the help! Much appreciated!