How can I make a player's tools/backpack save?

Hello! I have recently started work on a new game when I ran into an issue. (I have been trying to make this work for HOURS before eventually turning to the forum.) How can I make players’ backpacks save?

I searched through google, youtube, nothing really worked. Some scripts worked but then sometimes I’d lose a tool or the tool wouldn’t save if I was holding it. Sometimes things saved for me, but not for my friend.
So I’m just here to ask if anyone has/could write a script that could save everything in the player’s backpack. Thanks :slight_smile:

I won’t write the whole script - but here’s a few pointers as to how you could do it.

  1. Use an array to save them
  2. Iterate through the player’s backpack to get the tools they have (btw equipped tools will be in the character)
  3. Have all the tools in ServerStorage and 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!