Send a lot of datastore requests without queue

I have a datastore that loads up 7007 different entries for a Canvas. It can take up to 10-20 minutes to load it up fully, and I want to know how to speed it up.
script;


local datastore = game:GetService("DataStoreService")

local DS2 = datastore:GetDataStore("TilesNewer")
--local va =datastore:GetDataStore("Tiles")
local asv = workspace.Baseplate.Canvas:getChildren()
local numb = 0
local finishedloading = false
local loadingmsg = Instance.new("Message",workspace)
loadingmsg.Text = "Loading up the Canvas, It will take up to several minutes."
game.Lighting.allslots.Value = #asv - 1
loadingupslot = false
for i=1, #asv do
	if asv[i]:IsA("ImageButton") then
		--repeat wait() until loadingupslot == false
		--print(numb)
		--table.insert(stupidpeople,asv[i])
		--va:SetAsync(tostring(asv[i].Name),{1,1,1})
			task.spawn(function()
			numb = numb + 1
			game.Lighting.slotsloaded.Value = numb
			if numb == (#asv - 1) then
					--loadingmsg:Destroy()
					loadingmsg:Destroy()
				finishedloading = true
				game.Lighting.Loading.Value = false
				local loadingmsgv = Instance.new("Message",workspace)
				loadingmsgv.Text = "Done! You can now start painting!"
				game.Debris:AddItem(loadingmsgv,2)
				end
		end)
		local ready = false
		task.spawn(function()
		local data
		local success, response = pcall(function()
			data = DS2:GetAsync(tostring(asv[i].Name))
			end)
			if success then
				ready = true
			if data ~= nil then
			--print(data[1])
			--print(data[2])
			--print(data[3])
			asv[i].BackgroundColor3 = Color3.new(data[1],data[2],data[3])
					asv[i].ImageColor3 = Color3.new(data[1],data[2],data[3])
				end
			else
				ready = true
				--DS2:SetAsync(tostring(asv[i].Name),{1,1,1})
			end
		end)
		repeat wait() until ready == true
		--print("Slot "..asv[i].Name.." has loaded.")
		end
	end
--for i=1,#stupidpeople do
--	local data = va:GetAsync(tostring(stupidpeople[i].Name))
--	if data then
--		local vars = workspace.Baseplate.Canvas:FindFirstChild(stupidpeople[i].Name)
--		if vars ~= nil then
--			if data ~= nil then
--				vars.BackgroundColor3 = Color3.new(data[1],data[2],data[3])
--			end
--		end
--	end
--end

Why save every pixel value to a new key? Save it as a table instead.

local datastoreService = game:GetService("DataStoreService");

local canvasStore = datastoreService:GetDataStore("Canvas_1");
local canvas = game:GetService("Workspace").Canvas;

local currentPainting = "Painting1";

local function serialize(color: Color3)
	return ("%d,%d,%d"):format(color.R * 255, color.G * 255, color.B * 255);
end

local function deserialize(str: string)
	return Color3.fromRGB(table.unpack(str:split()))
end

local function save(tries)
	tries = tonumber(tries) or 3;
	
	local data = {};
	for _,p in ipairs(canvas:GetChildren()) do
		data[tonumber(p.Name)] = serialize(p.Color);
	end
	
	local finalErr;
	while tries > 0 do
		local success, err =  pcall(canvasStore.SetAsync, canvasStore, currentPainting, data);
		if success then return; end

		finalErr = err;
		tries -= 1;
	end
	
	warn(("Could not save \"%s\" \n%s"):format(currentPainting, finalErr));
end

local function load()
	local success, data = pcall(canvasStore.GetAsync, canvasStore, currentPainting);
	if not success then
		warn(data);
		return;
	end
	
	for i,c in ipairs(data or {}) do
		canvas[tostring(i)].Color = deserialize(c);
	end
end

load();
game:BindToClose(save);

The canvas is controlled by multiple people, and they can edit it.

Am I missing out something? You can still implement my method even though many people are editing it at once.

Not really, I dont know why I even responded because I didnt read the script fully lol. Thank you!

1 Like