Roblox pcall datastore not saving cash

Heres code:

local DataStoreService = game:GetService("DataStoreService")
local Cashdatastore = DataStoreService:GetDataStore("CashDS")

game.Players.PlayerAdded:Connect(function(Player)
	local Cash = Instance.new("NumberValue")
	Cash.Name = "Cash"
	Cash.Parent = Player

	local Success, Error

	Success, Error = pcall(function()
		Data = Cashdatastore:GetAsync(Player.UserId)
	end)

	if Success then
		if Data then
			Cash.Value = Data
			print("Loaded "..Player.UserId)
		else
			Cash.Value = 500
			print(Player.Name.." is new to the game")
		end
	else
		print(Error)
	end
end)
--------------------------------Saving part----------------------------------------
game.Players.PlayerRemoving:Connect(function(Player)
	local success, errorMsg

	success, errorMsg = pcall(function()
		Cashdatastore:SetAsync(Player.UserId, Player.Cash.Value)
	end)

	if success then
		print("Saved "..Player.UserId)
	else
		print(errorMsg)
	end
end)

I only get this in output:

image

i have two more datastores that are working

Might be because server is closing too fast.

Try:

game:BindToClose(function()
    if game:GetService("RunService"):IsStudio() then
        wait(3)
    end
end)

Roblox pcall datastore not saving cash
Roblox pcall datastore not saving cash

It’s because your second pcall is missing the argument
success, errorMsg = pcall(function()
Cashdatastore:SetAsync(Player.UserId, Player.Cash.Value)
end)

should be
success, errorMsg = pcall(function(Player)
Cashdatastore:SetAsync(Player.UserId, Player.Cash.Value)
end, Player)

Just so you know. That is wrong. Pcalls do not have “Player” parameter.