I recently read more in depth about how data store works on the roblox wiki, and found that each key is limited to about 2^16 string characters of data (64 kibibytes). Which means using JSON on tables depends on how big the table is, which causes a HUGE problem for my project.
Here's an example:
local player_data = {} local http = game:GetService("HttpService") local data = game:GetService("DataStoreService"):GetDataStore("Test") data:SetAsync("player_info", http:JSONEncode(player_data)) print(data:GetAsync("player_info") and "Data found" or "Data not found") -- Result is as expected for i = 1,2^16 do table.insert(player_data, '.') end data:SetAsync("player_info",http:JSONEncode(player_data)) -- Says value is to large! print(data:GetAsync("player_info") and "Data found" or "Data not found")
Please help! This means things like chat logs saving, complex stats saving, and anything else that involves a lot of memory to be stored based off players is very limited! Is there any way around this?
You could always create a table, separate the string into multiple parts and insert them into the table.
local player_data = {} local http = game:GetService("HttpService") local data = game:GetService("DataStoreService"):GetDataStore("Test") function split_string(str) local length = 2^16 local result = {} for i=1, #str do if i % length == 0 then -- check if "i" is divisible by length local string_part = str:sub(i-length, i) -- or string.sub(string_part, i-length, i) result[#result + 1] = string_part -- table.insert uses too much memory compared to this :) end end return result end for i=1, 2^16 do player_data[#player_data + 1] = '.' end player_data = split_string(player_data) data:SetAsync("player_info", http:JSONEncode(player_data))
To read it:
local player_data = data:GetAsync("player_info") and "Data found" or "Data not found") for index, value in next, http:JSONDecode(player_data) do print(index, value) end