Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I handle the maximum amount of data memory?

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

0

What's the point of saving the keys on the datastore?

0

I want to be able to read the data from all players

1 answer

i don't know if this will work but local a variable as another datastore and if one is full, error saving data, put them in the other data store. Then put if key is not found in one data store search the other. I don't know if their is an efficient way to do it, but that's what i came up with.

This discussion is preserved as it was. New answers, comments, and votes are closed.