I want to make it when you leave it saves your tools. I’m saving a table into a datastore but it doesn’t save or something is wrong but I don’t see it. So this is why I’m asking for help
The issue is that its just not working and I don’t get. I’ve been working on this for almost all day debugging one script.
I’ve been trying putting prints in specific places but It doesn’t help.
local DSS = game:GetService("DataStoreService")
local Inventory = DSS:GetDataStore("Inventory")
local function getInv(folder) ------------------------------ Gets contents of a folder and converts into a table
local Children = folder:GetChildren()
local tab = {}
for i = 1, #Children do
local child = Children[i]
if child then
table.insert(tab, child.Name)
print(child.Name)
end
end
return tab
end
game.Players.PlayerAdded:Connect(function(plyr)
local InvFolder = Instance.new("Folder", plyr) ---------- Inventory Folder
local tries = 0
InvFolder.Name = "Inventory"
local function getTab() ------------------------------- Gets the inventory table from datastore
InvTab = Inventory:GetAsync(plyr.UserId)
end
local success, err = pcall(getTab)
while not success do ------------------------------------------- If not successful retry
tries = tries + 1
if tries >= 10 then
plyr:Kick("Data failed to load rejoin")
else
success, err = pcall(getTab)
end
end
print(InvTab)
if InvTab then ----------------------------------------------- Check if there is data to load
print("InvTab Is Not Nil")
for i, v in pairs(InvTab) do
if v then
local item = game.ServerStorage.Items:FindFirstChild(v)
if item then
item:Clone().Parent = InvFolder ---------------------------- Load items into inventory
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plyr)
local folder = plyr:WaitForChild("Inventory")
local success, err = pcall(function()
Inventory:SetAsync(plyr.UserId, getInv(folder))
end)
end)
I just don’t see anything wrong with this script. If someone could tell me what I’m doing wrong thanks.