How to use DataStore2.Combine correctly?

Hello, so I’m trying to use DataStore2.Combine Correctly. So I have multiple scripts that use different datastores2. Do I Combine them for each script that they are used or just once in a main script?

EX:

Script 1

local DataStore2 = require(ServerScriptService.DataStore2)
DataStore2.Combine("MainData", "Pets", "Weapons", "Armor", "Something", "SomethingElse")
Players.PlayerAdded:Connect(function(player)
    local PetsStore = DataStore2("Pets", player) 
end)

Script 2

local DataStore2 = require(ServerScriptService.DataStore2)
---- No Combine
Players.PlayerAdded:Connect(function(player)
    local WeaponsStore = DataStore2("Weapons", player) 
    local ArmorStore = DataStore2("Armor", player) 
end)

Script 3

local DataStore2 = require(ServerScriptService.DataStore2)
---- No Combine
Players.PlayerAdded:Connect(function(player)
    local SomethingStore = DataStore2("Something", player) 
    local SomethingelseStore = DataStore2("Somethingelse", player) 
end)

Would this work? Thanks for the help!

1 Like

You can combine your DataStore2s at any time, just make sure you only do it once per DataStore2 name. Your current script is correct and Combine can be used this way but it might be more readable to combine in relevant scripts only, so for example Script 2 can combine Weapons/Armor instead of Script 1 and likewise Script 3 can combine the somethings.

Internally what Combine does is take anything after the first string and associate them with the first string you pass, so you can script as if you’re working with several DataStores but DataStore2 will handle combining them all into one bigger table and save that.

6 Likes

Can you elaborate on this? What do you mean by once per DS2 name? :sweat_smile:

What it says on the tin: the name of a DataStore2, which is the first argument you pass when you call DataStore2. In Combine, the first argument is the main store name you want to use and the other arguments are the names of other DataStore2s that you want to include in the first one.

DataStore2("THIS_IS_THE_NAME", player)

DataStore2.Combine("main", "another_ds2", "third_ds2", ...)
1 Like