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!
You should only need one key, of course you will still need Stats1 & Stats2 (the keys are referencing the same thing anyway)