Using scope to separate Studio save data from Live Servers

So, I heard you can make use of scopes with datastores to keep things more organized, and even use it to keep save data on Studio isolated from the live servers. Of course, I’m aware you can just make a backup world for this, but I’d like to know these scopes are actually utilized anyway.

To my understanding, having these two lines for the same datastore will create the “global” scope by default, and a second scope.

local dataStore = DataStoreService:GetDataStore("PlayerData")
local dataStore = DataStoreService:GetDataStore("PlayerData", "Studio")

But as far as I understand on the Roblox Data Stores page, there’s nothing explaining how you would swap between these scopes. The only place I can imagine identifying the scope would be when you call :GetAsync / :UpdateAsync, but I’m not sure.

I feel like i’m misunderstanding something, but my understanding is that, with the use of scopes, on the same script with the same keys, you can separate save data between studio and live servers.

As your code snippet currently stands the second assignment would override the first, but you have the right idea.

local dataStore1 = DataStoreService:GetDataStore("PlayerData")
local dataStore2 = DataStoreService:GetDataStore("PlayerData", "Studio")

dataStore1:GetAsync("Key") --Retrieves data for key from non-scoped DataStore.
dataStore2:GetAsync("Key") --Retrieves data for key from scoped DataStore.

Scopes allow you to compartmentalize data under the same DataStore instance instead of using several DataStore instances to achieve a similar result.

1 Like

Let me write you a simple iteration of something I used to do:

local Version = "1.0.0"
local IsStudio = game:GetService("RunService"):IsStudio()
local Datastore = DataStoreService:GetDataStore("PlayerData", if IsStudio then Version.."DEV" else Version)

you can also just omit Version for this:

local IsStudio = game:GetService("RunService"):IsStudio()
local Datastore = DataStoreService:GetDataStore("PlayerData", if IsStudio then "DEV" else "LIVE")
1 Like

Wish I could mark both you and @IDoLua 's comments as the solutions, thanks a lot for the explanation! Makes much more sense now.