Inventory Save Script not operating properly

Hello DevForum,
Today I am trying to develop a save inventory system, today I tried using this tutorial: How to save your players' inventory items
However, when I copy and pasted the script into my game I couldn’t get it to work. Linked below is the script. What exactly am I doing wrong? Thanks for reading!

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 = tool[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)

local tool = tool[name] This should be local tool = tools[name]

1 Like

Thank you so much for the assistance!