this datastore saves data through a folder but for some reason it errors “invalid arguement to pairs table expected got nil”
in line 10
local ds = game:GetService("DataStoreService"):GetDataStore("some")
local folder = game.ReplicatedStorage.EconomyStuff.Cloud
local folder3 = game.ReplicatedStorage.EconomyStuff.Leaf
local folder4 = game.ReplicatedStorage.EconomyStuff.Mist
local folder7 = game.ReplicatedStorage.EconomyStuff.Sand
local folder13 = game.ReplicatedStorage.EconomyStuff.Stone
local folder14 = game.ReplicatedStorage.EconomyStuff.Points
local values = ds:GetAsync("some")
for i,v in pairs(values) do
for i,b in pairs(folder:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
for i,v in pairs(values) do
for i,b in pairs(folder3:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
for i,v in pairs(values) do
for i,b in pairs(folder4:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
for i,v in pairs(values) do
for i,b in pairs(folder7:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
for i,v in pairs(values) do
for i,b in pairs(folder13:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
for i,v in pairs(values) do
for i,b in pairs(folder14:GetChildren()) do
if v.Name == b.Name then
b.Value = v.Value
end
end
end
game:BindToClose(function()
local folder = game.ReplicatedStorage.EconomyStuff.Cloud
local folder3 = game.ReplicatedStorage.EconomyStuff.Leaf
local folder4 = game.ReplicatedStorage.EconomyStuff.Mist
local folder7 = game.ReplicatedStorage.EconomyStuff.Sand
local folder13 = game.ReplicatedStorage.EconomyStuff.Stone
local folder14 = game.ReplicatedStorage.EconomyStuff.Points
local toSave = {}
local success,err = pcall(function()
for i,v in pairs(folder:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
for i,v in pairs(folder3:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
for i,v in pairs(folder4:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
for i,v in pairs(folder7:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
for i,v in pairs(folder13:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
for i,v in pairs(folder14:GetChildren()) do
local valuetable = {}
valuetable.Name = v.Name
valuetable.Value = v.Value
table.insert(toSave,valuetable)
end
ds:SetAsync("some",toSave)
end)
if success then
print("saved!")
else
print("something went wrong while saving")
warn(err)
end
end)