local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local CardStore = DataStoreService:GetDataStore("PlayerCardList")
local CardService = require(script.CardHandler)
local CardCache = {}
local function createDefaultDeck()
return {
{
["Name"] = "boyparis",
["Color"] = 6865280869,
["Display"] = 6873565000,
["Power"] = 400,
["Health"] = 5000,
["WhiteCost"] = 10,
["RedCost"] = 3,
["BlueCost"] = 3,
["GreenCost"] = 3,
["YellowCost"] = 3,
["Trigger"] = nil,
["Effect"] = nil,
["Model"] = 6877137987
},
{
["Name"] = "nil",
["Color"] = 6865283271,
["Display"] = 6865303020,
["Power"] = 50,
["Health"] = 50,
["WhiteCost"] = 1,
["RedCost"] = 1,
["BlueCost"] = 1,
["GreenCost"] = 0,
["YellowCost"] = 0,
["Trigger"] = nil,
["Effect"] = nil,
["Model"] = 6877137987
}
}
end
local function playerAdded(player)
local success, data = pcall(function ()
return CardStore:GetAsync(player.UserId)
end)
if success then
if data then
CardCache[player.UserId] = data
else
CardCache[player.UserId] = createDefaultDeck()
end
else
-- Handle case of error; kick, block saving, etc.
warn(string.format("Could not load data for %s: %s", player.Name, data))
end
print(CardCache[player.UserId])
local pos = 0
for _, card in pairs(CardCache[player.UserId]) do
local card = CardService.Unserialize(card)
card.Position = UDim2.new(pos,0,0,0)
pos += 0.18
print(card)
-- Never really recommend interacting with PlayerGui from a server script
-- especially if it's to modify a Gui and not for a special reason.
card.Parent = player.Backpack.Deck
end
end
Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end
This is my script, what i wanted to know is how cn I make CardCache a global variable and then how could I access it?