local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local CardStore = DataStoreService:GetDataStore("PlayerCardList")
local CardService = require(game.ReplicatedStorage.Modules.CardService)
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
for _, card in pairs(CardCache[player.UserId]) do
local card = CardService.Unserialize(card)
card.Position = UDim2.new(0,0,0,0)
card.Parent = player.Backpack.Deck
print(player)
end
CardService.CardCache = CardCache
end
Players.PlayerAdded:Connect(playerAdded)
I have a problem with the playeradded function in this script, it says Deck is not a valid member of Backpack despite being there and using :WaitForChild(“Deck”) makes the script yield forever
It is likely that Deck is not replicated in time and the infinite yield issue kicks in after a certain amount of time that is really short. Try adding a second argument to fix that.
However, I’m rather confused why you are storing that in Backpack and not anywhere else.
Alternatively, try storing every possible GUI elements in a single folder in ReplicatedStorage and then allow server to store the cards properties if they ever are fixed. If that’s not the case and the cards have unique values, that’s a little more complicated.
Once you have the “compressed” information, you can just replicate the cards to the player to assumingly hold them visible from the client whenever the client requests them. The request will ask the server to check its cache of cards for the player and then replicate as accordingly and correspondingly. They will access the folder with the GUI elements, which then will be cloned to the player’s “hand”.
Yeah that’s what im doing, the cards are customized so the script generates them from the cache, and i thought doing that as soon as possible would be the better option, I wanted to do this to remove the gui elements from the folder as the cards were drawn, but i think i could just transfer the cache to a module that handles player interactions that removes the cards from said list and resets upon a match ending.