Trying to make a Daily Experience Notification System, DataStores limit it. What to do?

I am attempting to make a system, where a DataStore is created with today’s date, and any players who join the game, have their userID added to it, as seen below:

local today = tostring(os.date("%x"))
local dss = game:GetService("DataStoreService")
local todayLogs = dss:GetDataStore(today)
local Players = game:GetService("Players")

local function plrAdded(plr:Player)
    local success, errormsg = pcall(function()
		todayLogs:IncrementAsync(tostring(plr.UserId),1)
	end)
end

Players.PlayerAdded:Connect(plrAdded)

for _,i in pairs (Players:GetPlayers()) do
	task.spawn(function()
		plrAdded(i)
	end)
end

Then, the next day, the game would pull entries from what is now today’s logs (but would be yesterday’s then), and attempt to send them a notification using ROBLOX’s experience notifications.

local yesterday = tostring(os.date("%x", os.time()-86400))
local today = tostring(os.date("%x"))

local plrs = game:GetService("Players")
local scripts = game:GetService("ServerScriptService")
local cheese = require(scripts.monetization.offGameNotifs)

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore(today.." completed")
local options = Instance.new("DataStoreOptions")
options.AllScopes = true

local DataStore = dss:GetDataStore(yesterday, "", options)

-- This will be used to store the retrieved userIDs and Inventory
-- Each key will be a players userID, and the content of the key will be their inventory!
local dataDictionary = {}

-- Get all the stored keys under our Data Store
local listSuccess, pages = pcall(function()
	return DataStore:ListKeysAsync()
end)

local done = nil
local success, errormsg = pcall(function()
	done = ds:GetAsync("sent???")
end)

if done == nil then
	print("proceed")
	if listSuccess then
		print("proceed... again...")
		local index = 0
		while true do
			local items = pages:GetCurrentPage()
			for _, v in ipairs(items) do
				-- Take current key + its associated value and write it into the dictionary.
				local value = DataStore:GetAsync(v.KeyName)
				dataDictionary[v.KeyName] = value
			end
			index += 1
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
		end
		print("total entries: "..index)
		local success, errormsg = pcall(function()
			ds:SetAsync("activated?",true)
		end)
		for id,val in pairs(dataDictionary) do
			if tonumber(id) then
				cheese:AttemptSendNotification(tonumber(id))
			end
		end
	end
end

The issue I am running into, is the above code quickly overwhelms my game’s DataStores, as seen in this video. FWIW, there were a couple to a few hundred keys in that DataStore. Even adding a task.wait in the loop at the end does not help

How could I fix this issue so it’s not a problem? I do not need this to affect my other DataStores.

i suggest using profileservice which does have a lot of functionality also saves you from dataloss
ProfileService

Did you even read my post?

I will not use ProfileService for this. I use it already for the saving of player stats that actually matter (and not for the purpose of trying to cheese D1 Retention). ProfileService also needs to be loaded and released, especially if the player is in the game during attempts to send notifications, and that would add layers of complications vs. just using ROBLOX’s DataStores which allow you to access them whether or not the player is present.

DataStore does not like many requests, one thing you could try and do is have a batch system, so rather then having to iterate through every single item and use GetAsync on all of them, you can do sections at a time cutting down on cost.

This isn’t the best solution but it should help if you don’t get any other suggestions.

2 Likes

That’s what I’ve been thinking, having each server create their own key. Having a table generated, every player that plays has their userID inserted into it, and then right before the server closes, the server sets the value of its key to be the table of all the userIDs.

If I utilize this within the scope of DataStores, I can probably only do this for 50 servers a day or something.