Here is the full script, what it prints is “new detected” which means the data received was nil
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
function PosInArray (dictionary, PositionInDictionary)
local Keys = {};
for Key, Value in pairs(dictionary) do
table.insert(Keys, Key);
end
return dictionary[Keys[PositionInDictionary]];
end
function printTable(t)
local str = ""
for i, v in ipairs(t) do
str = str .. string.format("\t[%d] = %f,\n", i, v)
end
print(string.format("local tab = {\n%s}", str))
end
game.Players.PlayerAdded:Connect(function(Player)
local Success = false
local BackPack = Player.Backpack
local Data = DataStore:GetAsync("Items_"..tostring(Player.UserId))
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local money = Instance.new("IntValue",leaderstats)
money.Name = "₡"
money.Value = 0
leaderstats.Parent = Player
local role = Instance.new("StringValue",leaderstats)
role.Name = "Role"
role.Value = "None"
leaderstats.Parent = Player
if Data ~= tostring(nil) and not RunService:IsStudio() then
if Data[1] ~= nil and Data[2] ~= nil and Data[3] ~= nil and Data[4] ~= nil then
wait(1)
money.Value = Data[1]
local d = true
local storage = game.ServerStorage
local resources = Data[2]
local backpack = Data[3]
local amounts = Data[4]
if resources[1] ~= nil then
print(Data[1])
printTable(Data[2])
printTable(Data[3])
printTable(Data[4])
local resourceslist = {"Stone","Wood","Coal","Iron","Diamond","Obsidian","Leaves","Sand","Glass","Carrot","Tomato","Potato","Corn"}
for i,v in pairs(resourceslist) do
game.ServerStorage.PlayerData:FindFirstChild(Player.Name):FindFirstChild(v).Value = resources[v]
if resources[i] > 0 then
d = false
end
end
for count,z in pairs(backpack) do
local obj = workspace
for i,v in pairs(storage.Grabbables.Boxes:GetChildren()) do
if v.Name == z then
obj = v
end
end
for i,v in pairs(storage.Grabbables.Drops:GetChildren()) do
if v.Name == z then
obj = v
end
end
for i,v in pairs(storage.Grabbables.Tools:GetChildren()) do
if v.Name == z then
obj = v
end
end
if obj ~= workspace then
obj:Clone()
for i,v in pairs(obj:GetDescendants()) do
if v.Name == "Owner" then
v.Value = Player.Name
elseif v.Name == "Amount" then
v.Value = amounts[count]
elseif v.Name == "BillboardGui" then
local parentname = v.Parent.Name
if v.Parent.Name == "Handle" then
parentname = v.Parent.Parent.Name
end
v.DROP.Text = amounts[count].."x "..parentname
end
end
else
print("lmao object is workspace, name is "..tostring(z))
end
end
if #backpack == 0 and d == true then
print("new detected")
local cloned1 = storage.Axe:Clone()
local cloned2 = storage.Pickaxe:Clone()
cloned1.Parent = Player.Backpack
cloned2.Parent = Player.Backpack
else
print("Loaded")
end
else
print("new detected")
local cloned1 = storage.Axe:Clone()
local cloned2 = storage.Pickaxe:Clone()
cloned1.Parent = Player.Backpack
cloned2.Parent = Player.Backpack
end
end
else
local storage = game.ServerStorage
print("new detected")
repeat wait() until Player.Character
wait(0.5)
local cloned1 = storage.Axe:Clone()
local cloned2 = storage.Pickaxe:Clone()
cloned1.Parent = Player.Backpack
cloned2.Parent = Player.Backpack
end
end)
function save(Player)
local PlrData = {}
local Resources = {}
local data = game.ServerStorage.PlayerData:FindFirstChild(Player.Name)
--stone,wood,coal,iron,diamond,obsidian,leaves,sand,glass,carrot,tomato,potato,corn
Resources["Stone"] = data.Stone.Value
Resources["Wood"] = data.Wood.Value
Resources["Coal"] = data.Coal.Value
Resources["Iron"] = data.Iron.Value
Resources["Diamond"] = data.Diamond.Value
Resources["Obsidian"] = data.Obsidian.Value
Resources["Leaves"] = data.Leaves.Value
Resources["Sand"] = data.Sand.Value
Resources["Glass"] = data.Glass.Value
Resources["Carrot"] = data.Carrot.Value
Resources["Tomato"] = data.Tomato.Value
Resources["Potato"] = data.Potato.Value
Resources["Corn"] = data.Corn.Value
local BackPack = Player.Backpack
local BackPackItems = {}
local BackpackAmounts = {}
for i,v in ipairs(BackPack:GetChildren()) do
local amnt = 1
for i,v in pairs(v:GetDescendants()) do
if v.Name == "Amount" then
amnt = v.Value
end
end
table.insert(BackPackItems,v.Name)
table.insert(BackpackAmounts,amnt)
end
local money = Player.leaderstats["₡"].Value
table.insert(PlrData, money)
table.insert(PlrData, Resources)
table.insert(PlrData, BackPackItems)
table.insert(PlrData,BackpackAmounts)
DataStore:SetAsync("Items_"..tostring(Player.UserId), PlrData)
print("saved")
end
game.Players.PlayerRemoving:Connect(function(Player)
if not RunService:IsStudio() then
save(Player)
end
end)
local Players = game.Players
game:BindToClose(function()
if not RunService:IsStudio() and #Players:GetPlayers() > 1 then
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(save)(player)
end
end
end)
also you should ignore the first 2 functions because they are for printing stuff in published game or getting position in dictionaries