What am I doing wrong here? - data stores

Hey everyone! I’ve been working on a placement system for a little project of mine, and I’m having some issues with my inventory saving. It will only save the player’s data 30% of the time. I’ve been trying to fix the problem for about an hour now. So far, the data save works in terms of loading the player’s data, just not actually saving it (found this out by using print). So what’s the issue here? Am I doing something wrong?

Here’s the code:

local players = game.Players
local dataStorageService = game:GetService("DataStoreService")
local dataStore = dataStorageService:GetDataStore("HazDataStore1")

players.PlayerAdded:Connect(function(player)
	local newModule = script.InventoryModule:Clone()
	newModule.Parent = player
	local inventory = require(newModule)
	
	local save 
	local success, errormsg = pcall(function()
		save = dataStore:GetAsync("User-"..player.UserId)
	end)

	if success and save then
		for index, object in pairs(save) do
			if type(object) == "table" and inventory[object.id] then 
				local locatedObject = inventory[object.id]
				locatedObject.maxAmount = object.maxAmount
			end
		end
		print("data loaded!")
	else
		print("data failed to load!")
		warn(errormsg)
	end
end)

players.PlayerRemoving:Connect(function(player)
	local inventory = require(player.InventoryModule)
	local success, errormsg = pcall(function()
		dataStore:SetAsync("User-"..player.UserId, inventory)
	end)
	
	if success then
		print("data saved!")
	else
		print("data failed to save!")
		warn(errormsg)
	end
end)

try repeat saving maybe i hear games have datasaving problems if they are big enough

players.PlayerRemoving:Connect(function(player)
	local inventory = require(player.InventoryModule)
repeat
	local success, errormsg = pcall(function()
		dataStore:SetAsync("User-"..player.UserId, inventory)
	end)
if success then
		print("data saved!")
	else
		print("data failed to save!")
		warn(errormsg)
	end
	until success
end)