1.What do you want to achieve? A working inventory saver
2.What is the issue? Code won’t work
3.What solutions have you tried so far? Youtube and the DevForum
Here is my code:
local ToolFolder = game:GetService(“ServerStorage”):WaitForChild(“SavedTools”)
local DataStoreService = game:GetService(“DataStoreService”)
local SaveData = DataStoreService:GetDataStore(“SaveData”)
game.Players.PlayerAdded:Connect(function(Player)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
local ToolData
local success, whoops = pcall(function()
ToolData = SaveData:GetAsync(Player.UserId)
end)
if success and ToolData then
print("Data successfully loaded!")
for i, v in pairs(ToolData)do
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
else
warn(whoops)
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
local success, whoops = pcall(function()
SaveData:SetAsync(Player.UserId, ToolTable)
end)
if success then
print("Data successfully saved!")
else
warn(whoops)
end
Are there any errors in the output? If yes, could you show a screenshot of it (or just copy the error text from the output)? When you mean the code doesnt work, do you mean like nothing works at all? It never saves your tools when you leave the game?
Make sure no values are nil, so I recommend printing ToolFolder, Backpack, and StarterPack before the loop through ToolData, and make sure ToolData is not nil either
Then it’s something else with your code. I can’t help any further right now so either you’re gonna have to figure it out yourself or have someone else help sorry.