I have used a script that supposedly saves the player’s tools in their inventory. But it has not.
Script:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local player_data = DataStoreService:GetDataStore("player_data")
local tools = ServerStorage.Tools
local inventories = ServerStorage.Inventories
Players.PlayerAdded:Connect(function(client)
local key = "client_" .. client.UserId
local inventory = player_data:GetAsync(key) -- Not worrying about pcalls, do that yourself
local inventory_folder = Instance.new("Folder")
inventory_folder.Name = client.Name
inventory_folder.Parent = inventories
for _, name in ipairs(inventory or { }) do
local tool = tools[name]
tool:Clone().Parent = client.Backpack -- For the player to use
tool:Clone().Parent = inventory_folder -- For saving and loading
end
end)
Players.PlayerRemoving:Connect(function(client)
local key = "client_" .. client.UserId
local tools = { }
local inventory_folder = inventories[client.Name]
for _, item in ipairs(inventory_folder:GetChildren()) do
table.insert(tools, item.Name)
end
player_data:UpdateAsync(key, function(prev)
return tools
end)
inventory_folder:Destroy()
end)
If there are no tools within the player’s folder under Inventories then nothing can be saved. Your save works around the tools within the player’s folder so if there’s nothing then nothing saves.
I forgot to mention the tools are in the player’s backpack before they leave. How would you make it so all of the tools clone to the folder when they leave?
You can switch your leave event to this then if they’re exclusively on the player.
Players.PlayerRemoving:Connect(function(client)
local key = "client_" .. client.UserId
local tools = { }
local inventory_folder = inventories[client.Name]
local Character = client.Character
if Character then
for X, item in Character:GetChildren() do
if not item:IsA("Tool") then continue end
table.insert(tools, item.Name)
local tool = item:Clone() -- Maybe these few lines
tool.Name = item.Name -- ^
tool.Parent = inventory_folder -- ^
end
end
for _, item in client.Backpack:GetChildren() do
table.insert(tools, item.Name)
end
player_data:UpdateAsync(key, function(prev)
print(tools)
return tools
end)
inventory_folder:Destroy()
end)
Can you send a screenshot of your tools folder(ServerStorage.Tools) and everything in it? That error is occurring only because a tool with the specific name “Dishes” isn’t under the tools folder (ServerStorage.Tools)
No I’m saying can you check your ServerStorage.Tools folder to see if there’s a child called “Dishes”? If you’re adding tools that arent in the tools folder then it cant clone a non existing tool