Datastore not saving

Hi so I am trying to save players data but Im getting an error

Script

game:BindToClose(function(player)
	local success, errormessage = pcall(function()
		pointsData:SetAsync(player.UserId.."-Points", player.leaderstats.Points.Value)
		moneyData:SetAsync(player.UserId.."-Money", player.leaderstats.Money.Value)
		XPData:SetAsync(player.UserId.."-XP", player.leaderstats.XP.Value)
	end)

	if success then
		print("Data successfully saved!")
	else
		print("There was an error while saving the data")
		warn(errormessage)
	end

end)

Error

ServerScriptService.Datastores.Script:45: attempt to index nil with 'UserId'

BindToClose fires when the server closes? not when the Player leaves?

Plus, The Player isnt an argument for BindToClose

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.