This script is to store the player key in a large data store and store the player data with the player key in another data store. The current problem I am facing is that the large data store gets corrupted if it contains too many keys.
Since 260,000 characters can be stored in a data store and a key has an average of 27 characters, only about 9629 keys can be stored.
Example key: (savekey-100000000-100000000)
local DataStore = {}
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("GeneralSaveData", "Players")
function DataStore.GenerateDataKey(Player)
local GeneratedKey = ("savekey-" .. game.GameId .."-".. Player.UserId)
return GeneratedKey
end
function DataStore.SaveData(Player, Data)
local key = DataStore.GenerateDataKey(Player)
local data = Data
DS:SetAsync(key, data)
DS:UpdateAsync("_SavedPlayerKeys_1", function(knownKeys)
local InsertKey = true
for number, currentkey in pairs (knownKeys) do
if currentkey == key then
InsertKey = false
end
end
if InsertKey == true then
table.insert(knownKeys, key)
end
return knownKeys
end)
local PrintData = DS:GetAsync("_SavedPlayerKeys_1")
print "----------------------"
for _,v in pairs (PrintData) do
print (_,v)
end
end
return DataStore

2 comments
What's the point of saving the keys on the datastore?
I want to be able to read the data from all players