Players Data Doesn't Save And Pcall Isn't Working

I’ve been stuck on saving a players weapons for a while. The players weapons do not save, but the pcall does not print an error. Not errors are shown in the output, and I’ve already tried this in game.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")

print("Variables")

local player_data = DataStoreService:GetDataStore("player_data")

local tools = ServerStorage.ShopItems
local inventories = ServerStorage.Inventories

Players.PlayerAdded:Connect(function(client)
print("playerjoined")
	local key = "client_"..client.UserId
	local inventory = player_data:GetAsync(key)

for i,v in pairs(inventory) do
print(i,v)
end
	
local inventory_folder = Instance.new("Folder")
	inventory_folder.Name = client.Name
	inventory_folder.Parent = inventories
	print("folder created")
	print(tools)
	if inventory then
	     for _, name in ipairs(inventory) do ---PART THAT IS WORKING
		 local tool = tools[name]
		print("tools")
		tool:Clone().Parent = client.Backpack 
		tool:Clone().Parent = inventory_folder -- For saving and loading
		print("tools")
	end
	end
end)


Players.PlayerRemoving:Connect(function(client)
	print("PlayerLeft")
	local key = "client_".. client.UserId
	local tools = {}
	local inventory_folder = inventories[client.Name]
	
	for _, item in pairs(inventory_folder:GetChildren()) do
		table.insert(tools, item.Name)
	end
	
	local success, data = 
		pcall(player_data.UpdateAsync, player_data, key, function(prev)

		end)
	if not success then ---Success is underlined in blue
		print(error) -- this print call will only run if success is false
	else 
		return tools
	end
		inventory_folder:Destroy()
end)
	
print("done")
1 Like

You’re not doing anything in the function you pass to UpdateAsync. If the function passed doesn’t return anything, it won’t overwrite any data.

2 Likes