Only 1 tool gets saved in Save inventory Script

I want to save the player’s tools when he leaves, but only 1 gets saved, not all the others.
Here is my script:


function PlayerDataHandler:SaveInventory(player)
	for i, v in (player.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			print(v.Name)
			self:Update(player, "Inventory")
				table.insert(dataTemplate.Inventory, v.Name)
			
		end
	end
	
end

Hey, RaxelRbx! I will try to help you out! The information Is very limited but I will try my best to guess how It’s done

Try this code:

function PlayerDataHandler:SaveInventory(player)
    local inventoryData = {}

    for i, v in ipairs(player.Backpack:GetChildren()) do
        if v:IsA("Tool") then
            print(v.Name)
            table.insert(inventoryData, v.Name)
        end
    end
    
    self:Update(player, "Inventory", inventoryData)
end

1 Like

Thanks, I tried it and it worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.