Datastores function using keys, so if you have a datastore called Inventories and, for example, you want to save that player’s inventory separated from everyone else’s, you’d save it with an unique key, like the player’s userId. Here’s an example:
local InventoriesDatastore = game:GetService("DataStoreService"):GetDatastore("Inventories")
local Data = {
Health = 100,
Stamina = 43,
Weapons = {"M16","Glock","M1416","Revolver"},
PrimaryWeapon = "M16",
SecondaryWeapon = "Glock"
}
InventoriesDatastore:SetAsync(PlayerUserIdHere,Data)
This will save the table to the key I’ve set, which is the player user id, unique from anyone else.
Now if I wanted to save something to one unique datastore, I’d set a default key, a key I will always use to save that specific data, like so:
local MyGlobalDataStore= game:GetService("DataStoreService"):GetDatastore("GLOBALDATA")
local Data = {
Gold = 1504,
Jade = 258,
Tools = {"Pickaxe","Axe","Shovel","Rock"},
Money= 1972
}
MyGlobalDataStore:SetAsync("GLOBALDATA",Data)
Since this time I used the key GLOBALDATA, the data will be saved to that unique scope within the datastore, and if I save or load other data using that key, the same data will always be returned (Unless you change it for other data, obviously).
Alternatively, you can also use Global Datastores which will always save data to the same datastore without the need of a name. But this can be limited if you want to have multiple global datastores. Apologies if this gets confusing.