So I’m just here to ask if anyone has/could write a script that could save everything in the player’s backpack. Thanks
I won’t write the whole script - but here’s a few pointers as to how you could do it.
- Use an array to save them
- Iterate through the player’s backpack to get the tools they have (btw equipped tools will be in the character)
- Have all the tools in
ServerStorageand clone them to the player’s backpack depending on what they have (for loading owned tools)
So parts of it could look something like:
local function save(player)
local tools = {}
for _, tool in ipairs(player.Backpack:GetChildren()) do
table.insert(tools, tool.Name)
end
if player.Character:FindFirstChildOfClass("Tool") then
table.insert(tools, player.Character:FindFirstChildOfClass("Tool").Name)
end
--then, if you're already using a dictionary to save player data:
--add a sector named "Tools":
local playerData = {
["Tools"] = tools
}
--then go about saving the data:
local success, result = pcall(dataStore.SetAsync, dataStore, key, playerData)
end
Hope this helps!