I am making a game using DataStores and I want to use more than when DataStore to save different things. For Example: Have one DataStore for the players cash, xp, and level and one for the players health, walkspeed, and last CFrame (To load the players position when they join back on the game). My question is when using multiple DataStores do I need more than one key variable? Example:
local DataStoreService = game:GetService("DataStoreService")
local DataStoreCXL = DataStoreService:GetDataStore("CashXPLevel")
local DataStoreHWLC = DataStoreService:GetDataStore("HealthWalkSpeedLastCFrame")
local function Load(plr)
local key = "plr-"..plr.UserId
local key2 = "plr-"plr.UserId -- do I need this key?
local Stats1
local Stats2
pcall(function()
Stats1 = DataStoreCXL:GetAsync(key)
Stats2 = DataStoreHWLC:GetAsync(key2)
end)
if Stats1 then
-- Load data
else
-- More code
end
if Stats2 then
-- Load data
else
-- More code
end
end
local function Save(plr)
local key = "plr-"..plr.UserId -- the first key
local key2 = "plr-"..plr.UserId -- second key
pcall(function()
DataStoreCXL:SetAsync(key, SomeTable) -- Save the game stats
DataStoreHWLC:SetAsync(key2, SomeOtherTable) -- Save the players stats
end)
end
game.Players.PlayerAdded:Connect(Load)
game.Players.PlayerRemoving:Connect(Save)
I know the example is not in a working state it was just to show my idea.
Thanks for helping!

8 comments
You don't need to use separate data stores at all! You can save tables, the table will contain all values.
But if I do want to use two data stores do I need another key?
variable
You should only need one key, of course you will still need Stats1 & Stats2 (the keys are referencing the same thing anyway)
Thanks If you post that as a answer I will accept it! (:
you mean me?
Yes
hmm okay