I’m new to datastore, but I have a problem.
I want to store tables and I wrote these scripts:
Data Saver (saves for all players)
function saveAllData()
for num,plr in ipairs(game.Players:GetPlayers()) do
local function updateData()
return plr.leaderstats.ObbyCoins.Value
end
local function updateData2()
local items = {}
for i,v in ipairs(plr.GameConfigs.PlayerItems:GetDescendants()) do
items[i] = v.Value
print(items[i])
end
return items
end
local success,abc = pcall(function()
coinData:UpdateAsync(plr.Name,updateData)
itemData:UpdateAsync(plr.Name,updateData2)
end)
if success then
print(plr.Name .."'s Data Updated Successfully!")
else
error(plr.Name .."'s Data Updated Unsuccessfully Because Error: ".. abc)
end
end
end
Data Creator
function manageData(player)
local done,amount = pcall(function()
itemData:GetAsync(player.Name)
end)
local done2,amount2 = pcall(function()
itemData:GetAsync(player.Name)
end)
-------------------------------------------
if not done then
print("Creating Coin Data...")
local done,err = pcall(function()
coinData:SetAsync(player.Name,0)
end)
if done then
print("Data Created For:".. player.Name)
else
error("Process Failed Because Error "..err)
end
end
------------------------------------------
if not done2 then
print("Creating Item Data...")
local done,err = pcall(function()
itemData:SetAsync(player.Name,{})
end)
if done then
print("Data Created For:".. player.Name)
else
error("Process Failed Because Error "..err)
end
end
------------------------------------------
local done,amount = pcall(function()
player.leaderstats.ObbyCoins.Value = coinData:GetAsync(player.Name)
end)
local done,amount = pcall(function()
local itemTable = itemData:GetAsync(player.Name)
print(unpack(itemTable))
for i,v in ipairs(itemTable) do
if v == "RedTrail" then
BIH.createTrail("RedTrail",ColorSequence.new(Color3.fromRGB(0,0,0),Color3.fromRGB(255,0,0)),player,true)
end
end
end)
end
Basic Item Handler (or BIH, creates basic items like trails.)
local BItemHandler = {}
function BItemHandler.createTrail(name,color,player,boughtfirsttime)
local item = Instance.new("Trail")
item.Parent = player.character.Head
item.Color = color
item.Name = name
item.Enabled = true
item.Lifetime = 2
local att0 = Instance.new("Attachment",player.character.HumanoidRootPart)
att0.Name = "TrailAtt0"
att0.Position = Vector3.new(0,1,0)
local att1 = Instance.new("Attachment",player.character.HumanoidRootPart)
att1.Name = "TrailAtt1"
att1.Position = Vector3.new(0,-1,0)
item.Attachment0 = att0
item.Attachment1 = att1
if boughtfirsttime then
local itemOwn = Instance.new("StringValue",player.GameConfigs.PlayerItems)
itemOwn.Name = "itemTrail"
itemOwn.Value = name
end
end
return BItemHandler
But, It doesn’t saves or loads any data that I want.
What is the problem with these scripts?