Code:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local CardStore = DataStoreService:GetDataStore("PlayerCardListTEST")
local CardService = require(game.ReplicatedStorage.Modules.CardModule)
local MatchService = require(game.ReplicatedStorage.Modules.MatchService)
local CardCache = require(game.ServerStorage.Cache)
local function deepCopy(original)
local copy = {}
for k, v in pairs(original) do
if type(v) == "table" then
v = deepCopy(v)
end
copy[k] = v
end
return copy
end
local function playerAdded(player)
print(player.Name)
local success, data = pcall(function ()
return CardStore:GetAsync(player.UserId)
end)
if success then
if data then
CardCache[player.UserId] = data
local tempcache = deepCopy(CardCache[player.UserId])
MatchService.TemporaryCache[player.UserId] = tempcache
else
CardCache[player.UserId] = CardService.DefaultCards
local tempcache = deepCopy(CardCache[player.UserId])
MatchService.TemporaryCache[player.UserId] = tempcache
end
print(MatchService.TemporaryCache[player.UserId] ,
CardCache[player.UserId])
else
-- Handle case of error; kick, block saving, etc.
warn(string.format("Could not load data for %s: %s", player.Name, data))
end
end
game:BindToClose(function(player)
CardStore:UpdateAsync(function(CurrentData)
return CardCache[player.UserId]
end)
CardCache[player.UserId] = nil
end)
Players.PlayerAdded:Connect(playerAdded)
result:
13:58:40.863 Layered Accessories JSON is invalid! - Studio