DataStore not saving data

So my saving script saves a table which is the player’s inventory. For some reason the function doesn’t print the saved data message and ends with no output. I added BindToClose which cause this error: Not running script because past shutdown deadline (x10).

I’ve tried other things and that didn’t work and I don’t wish to be forced to move with DataStore2.
This is my code (Little bit inexperienced with DataStores)

local shop = script.Parent.Parent:WaitForChild("DataStoreAssetShop")
local inv = script.Parent.Parent:WaitForChild("DataStoreAssetInventory")
local Settings = script.Parent.Parent:WaitForChild("DataStoreAssetSettings")

local datastore = game:GetService("DataStoreService")
local InventoryData = datastore:GetDataStore("Inventory")

local InventoryValue = script.Parent.Values.Inventory

local function saveData(player)
	local saved, failed
	local dataTable = {InventoryValue.Value}
	if dataTable[1] == nil or dataTable[1] == "" then return error("Nil Index", 1) end
	
	while not saved do
		wait(.5)
		saved, failed = pcall(function()
			InventoryData:UpdateAsync(player.UserId, function(old)return dataTable end)
		end)
		if not saved then
			print("[ERR 1]")
			warn(failed)
		else
			print("Saved Data!")
			break
		end
	end
end

game:GetService("Players").PlayerRemoving:Connect(function(player)
	coroutine.wrap(saveData)(player)
end)

if game:GetService("RunService"):IsStudio() then
	game:BindToClose(function()
		for _, player in next, game:GetService("Players"):GetPlayers() do
			coroutine.wrap(saveData)(player)
		end
		wait(3)
	end)	
end

Anyone getting this issue or knows how to fix it? Please let me know asap! Thanks.

I suggest not using userdata(Int values, string values, ect…) to contain data; The best option is all array based data storage.

Example:

   local Data = {
    ["Money"] = 1;
    ["Items"] = {
    ["Sword"] = 1;
    };
     
     SaveDataFunction(Data)

Then when loading data do this

Data = LoadDataFunction(Player)
print(Data.Money) -->1

Or just take a look at this
https://www.roblox.com/library/6169155255/PlayerData-Class
and my many other examples

Thanks, I’ll look into this and see if this solves my current issue!