Hey, I’m trying to make a dataStore script that saves the amount of cards a player has, the card level, and whether or not the card is owned. I’m not sure what’s wrong with it.
local ds = game:GetService("DataStoreService"):GetDataStore("CardSaving")
local cards_folder = game.ServerStorage.Cards
game.Players.PlayerAdded:Connect(function(plr)
local cards_fold = Instance.new("Folder")
cards_fold.Name = "Cards"
cards_fold.Parent = plr
for _, v in pairs (cards_folder:GetChildren()) do
local card = Instance.new("Folder")
card.Name = v.Name
card.Parent = cards_fold
local cardOwned = Instance.new("BoolValue")
cardOwned.Name = "CardOwned"
cardOwned.Parent = card
local cardAmount = Instance.new("IntValue")
cardAmount.Name = "CardAmount"
cardAmount.Parent = card
local lvl = Instance.new("IntValue")
lvl.Name = "Level"
lvl.Parent = card
local Chloe = ds:GetAsync("Chloe".. plr.UserId)
local KEKI = ds:GetAsync("KEKI".. plr.UserId)
local Radley = ds:GetAsync("Radley".. plr.UserId)
local Sabaku = ds:GetAsync("Sabaku".. plr.UserId)
if v.Name == "Chloe" and Chloe ~= nil then
print("Getting the data")
local succ, msg = pcall(function()
cardOwned.Value = (Chloe)
cardAmount.Value = (Chloe)
lvl.Value = (Chloe)
end)
if not succ then
warn("Problem with getting and setting data "..msg)
end
elseif v.Name == "KEKI" and KEKI ~= nil then
local succ, msg = pcall(function()
cardOwned.Value = (KEKI)
cardAmount.Value = (KEKI)
lvl.Value = (KEKI)
end)
if not succ then
warn("Problem with getting and setting data "..msg)
end
elseif v.Name == "Radley" and Radley ~= nil then
local succ, msg = pcall(function()
cardOwned.Value = (Radley)
cardAmount.Value = (Radley)
lvl.Value = (Radley)
end)
if not succ then
warn("Problem with getting and setting data "..msg)
end
elseif v.Name == "Sabaku" and Sabaku ~= nil then
local succ, msg = pcall(function()
cardOwned.Value = (Sabaku)
cardAmount.Value = (Sabaku)
lvl.Value = (Sabaku)
end)
if not succ then
warn("Problem with getting and setting data "..msg)
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local succ, msg = pcall(function()
local Chloe = {}
local KEKI = {}
local Radley = {}
local Sabaku = {}
for _, v in pairs (plr.Cards:GetChildren()) do
local card = v
for _, v in pairs (card:GetChildren()) do
if card.Name == "Chloe" then
table.insert(Chloe,{v.Name, v.Value})
elseif card.Name == "KEKI" then
table.insert(KEKI, {v.Name, v.Value})
elseif card.Name == "Radley" then
table.insert(Radley, {v.Name, v.Value})
elseif card.Name == "Sabaku" then
table.insert(Sabaku, {v.Name, v.Value})
end
end
end
ds:SetAsync("Chloe"..plr.UserId, Chloe)
ds:SetAsync("KEKI"..plr.UserId, KEKI)
ds:SetAsync("Radley"..plr.UserId, Radley)
ds:SetAsync("Sabaku"..plr.UserId, Sabaku)
end)
if not succ then
warn("Problem with saving data ".. msg)
end
end)
Thanks!