I think it all boils down to personal preference, there’s nothing special about scopes in general from what I can tell. I do use them though, to keep things relatively clean.
EDIT
& in terms of hierarchy, it’d say it’s more so:
> DataStoreService
> Name | Scope [<default> Global / <custom> Named]
> Data
I can’t speak on how gracefully it’d scale with growth because I haven’t gotten to that point (although I can’t think of any reasons why it should be a problem), but here’s an excerpt on how I have it implemented:
local DatabaseKey = "GameUserData";
function Database:fetch(player)
local UUID = tostring(player.UserId)
local UserData = DataStore:GetDataStore(DatabaseKey, UUID)
if UserData then
for attempt = 1, MaxGetAttempts do
if attempt > 1 then
warn(string.format("DataStore GET attempt [%d/%d]"), attempt, MaxGetAttempts);
end
local success, response = pcall(function()
return UserData.GetAsync(UserData, "Profile")
end)
...
Oh yeah for sure, GetDataStore("GameUserData") uses the global scope, so the only difference with GetDataStore("GameUserData", "Scope") is that you’re using a new named scope as opposed to the default one.
Scopes are just used to partition data into other sections. Think of them like subfolders in a DataStore. When you don’t specify a scope, your DataStore actually still uses a scope - the default scope, which is “global”. Specifying a scope puts a DataStore at the same level as one without it.
When you get a DataStore, you open up the main folder which is the first string you specify to GetDataStore. When you don’t specify a scope, it defaults to global and opens the global subfolder. If you specify a scope, it creates and opens the new folder which is the scope you set.
I don’t think there is an real hierarchy for datastores, scopes are basically just another way to distinguish datastores similar to data store names.
Whenever you get a datastore with a new data store name and scope it adds an instance under DataStoreService, could this mean a memory leak if you get a unique datastore for each player?