"Datastore request was added to queue" even when it has a cooldown

I’m trying to make a saving system but it just keeps saying this when I spam the remote event,

I expected it to not happen since I’m waiting 2 (or more) seconds until I can save again.

This is my code (not the entire thing) ;

for i = 1, 25 do
	if cooldown then
		repeat task.wait(.5) until not cooldown
	else
		break
	end
	
	task.wait(.5)
end

cooldown = true
		
Store:SetAsync(Plr.UserId,EncodedData)
		
print('[SERVER] Saved loadout for ' .. Plr.Name .. '!')
		
task.wait(2)
		
cooldown = false

Anyone know how to make it stop warning this? Thanks in advance.

Full Code
local Storage = game:GetService('ReplicatedStorage')
local DS = game:GetService('DataStoreService')
local HS = game:GetService('HttpService')

local Store = DS:GetDataStore('Towers')

local Module = require(Storage.MainModule)

local cooldown = false

Storage.SaveData.OnServerEvent:Connect(function(Plr,Data:{ Loadout:{number},Towers:{number} })
	if Data['Loadout'] == nil or Data['Towers'] == nil then
		Plr:Kick('Data given by client does not have "Loadout" or "Towers".')
		
		return
	end
	
	for _, ID in Data.Loadout do
		if not table.find(Data.Towers,ID) and ID ~= 0 then
			Plr:Kick('Data given by client has specific IDs in "Loadout" but not in "Towers"')
			
			return
		end
	end
	
	local EncodedData = HS:JSONEncode(Data)
	
	if EncodedData then
		for i = 1, 25 do
			if cooldown then
				repeat task.wait(.5) until not cooldown
			else
				break
			end
			
			task.wait(.5)
		end
		
		cooldown = true
		
		Store:SetAsync(Plr.UserId,EncodedData)
		
		print('[SERVER] Saved loadout for ' .. Plr.Name .. '!')
		
		task.wait(2)
		
		cooldown = false
	else
		Plr:Kick('Suspected of exploiting, Data could not be converted into JSON')
	end
end)

Edit : If you are wondering, yes, it’s a server script. It would error if it was a local script.

I’m not too knowledgeable in DataStores, so I can’t give you in exact fix, I’ve had the same problem and it’s when you try to save to many data values too fast, the reason why the queue is getting filled up even with a wait in between is because data should have I believe 6 to 8 seconds it was. You are still saving too fast.

The best way around this would just to save one table of data.

1 Like

I actually had to wait 10 seconds for it to stop, it worked but I just didn’t like how I had to wait so long, because someone could be spamming it and no one else would be able to save their loadout, so I made it so that it only fires the remote event once their loadout hasn’t been changed for more than 2 seconds so that those warnings would appear less often, thanks for the help anyways!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.