How can a game server use IncrementAsync very quickly without cooldown

im making a game which has a “limited u” kinda system but i cant seem to make the serials increment quick enough due to the datastore cooldowns is there any other method i can use to create such a thing

thanks

Have you tried using MemoryStores instead? Writing to the same key has a 6 second limit. If your game updates in real time, use MemoryStores.

can you teach me how to use a memorystore

Haven’t worked with MemoryStores but I think they can be useful for what you’re doing. How about reading the MemoryStoreService documentation? Maybe it’s more useful than my explanations anyway.

Thank you i am testing out the memorystores

i dont think i can use memory stores because its not safe enough

type or local ds = game:GetService("DataStoreService")

local gc = {}
local getting = {}

local iqueue1 = {}
local completedi1 = {}

local iqueue2 = {}
local completedi2 = {}

local incid = 0


local function getstore(datastore,key)
	table.insert(getting,datastore..";"..key)
	local complete = false
	local data
	
	while not complete do
		local errormsg
		complete,errormsg = pcall(function()
			warn("getting async")
			data = ds:GetDataStore(datastore):GetAsync(key)
		end)
		if not complete then
			warn(errormsg)
			wait(1)
		end
	end
	

	if data == nil then
		data = "nil308952"
	end
	
	gc[datastore..";"..key] = data
	
	
	spawn(function()
		task.wait(4)
		gc[datastore..";"..key] = nil
	end)
	
	
	table.remove(getting,table.find(getting,datastore..";"..key))
	
	
	
	return data
end

local isrunning = false


local function incrementloop1()
	isrunning = true
	spawn(function()
	while wait() do
		local s,e = pcall(function()

			
			for i,maintb in pairs(iqueue1) do
		
			
			local incrementamount = 0
			
			local datastore
			local key
			local completedkeys = {}
		
						
			for i,v in pairs(maintb) do
			datastore = v[3]
			key = v[4]
			local amount = v[1]
						
			incrementamount += amount
			end
					
			if key then --if there are any requests	
						
						
						local complete = false
						local new

						while not complete do
							local errormsg
							complete,errormsg = pcall(function()
								warn("Inc async")
								new = ds:GetDataStore(datastore):IncrementAsync(key,incrementamount)
								warn("done")
							end)
							if not complete then
								warn(errormsg)
								wait(1)
							end
						end		
						
						
		
							
			local start = new - incrementamount
							
						
			for i,v in pairs(maintb) do
				local id = v[2]
				table.insert(completedkeys,id)
				local INCREMENTNUMBER = start + i
				
				completedi1[id] = INCREMENTNUMBER
			end
						
			
				for i,maintb1 in pairs(iqueue1) do --remove completed
							for numner,v in ipairs(maintb1)	 do
								if table.find(completedkeys,v[2]) then
									table.remove(maintb,numner)
							
								end
							end
								
								
								
								
				end		
							
							
				
						
						
						
						
			end
					
			
		end
				
				
				
			end)
			if not s then
				warn(e)
			end
	end
	end)
end

local function incrementloop2()
	isrunning = true
	spawn(function()
		while wait() do
			local s,e = pcall(function()


				for i,maintb in pairs(iqueue2) do


					local incrementamount = 0

					local datastore
					local key
					local completedkeys = {}


					for i,v in pairs(maintb) do
						datastore = v[3]
						key = v[4]
						local amount = v[1]

						incrementamount += amount
					end

					if key then --if there are any requests	


						local complete = false
						local new

						while not complete do
							local errormsg
							complete,errormsg = pcall(function()
								warn("Inc async")
								new = ds:GetDataStore(datastore):IncrementAsync(key,incrementamount)
								warn("done")
							end)
							if not complete then
								warn(errormsg)
								wait(1)
							end
						end		




						local start = new - incrementamount


						for i,v in pairs(maintb) do
							local id = v[2]
							table.insert(completedkeys,id)
							local INCREMENTNUMBER = start + i

							completedi2[id] = INCREMENTNUMBER
						end


						for i,maintb2 in pairs(iqueue2) do --remove completed
							for numner,v in ipairs(maintb2)	 do
								if table.find(completedkeys,v[2]) then
									table.remove(maintb2,numner)

								end
							end




						end		







					end


				end



			end)
			if not s then
				warn(e)
			end
		end
	end)
end



return function(datastore,key,method,writedata)
	local returndata
	
	if not isrunning then
		incrementloop1()
		incrementloop2()
	end
	
	
	if method == "Get" then
		
		local data = gc[datastore..";"..key]
		
		
		local getting = table.find(getting,datastore..";"..key)
		if getting then
			while getting do
				wait()
			end
			while not gc[datastore..";"..key] do
				wait()
			end
			
			data = gc[datastore..";"..key]
			
			
		end
		
		
		if not data then
			
			data = getstore(datastore,key) 
		end
		
		
		
		if data == "nil308952" then
			data = nil
		end
		
		
		returndata = data
	end
	
	
	if method == "Inc1" then
		incid += 1
		local myid = incid
		
	
	
		if not iqueue1[datastore..";"..key] then
			iqueue1[datastore..";"..key] = {}
		end
		
	
		table.insert(iqueue1[datastore..";"..key],{tonumber(writedata),myid,datastore,key})
		
		while not completedi1[myid] do
			wait()
		end
		local returnincrement = completedi1[myid]

		
		returndata = returnincrement
			
			
	end
	
	if method == "Inc2" then
		incid += 1
		local myid = incid



		if not iqueue2[datastore..";"..key] then
			iqueue2[datastore..";"..key] = {}
		end


		table.insert(iqueue2[datastore..";"..key],{tonumber(writedata),myid,datastore,key})

		while not completedi2[myid] do
			wait()
		end
		local returnincrement = completedi2[myid]


		returndata = returnincrement


	end

	
	return returndata
end
paste code here

i made a script which combinds requests together here it is :slight_smile: its fast now kinda smart