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.