DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 3837598027-tools

Hello so i got this script that i didn’t test yet, but its suppost to just give the player the tools he had in the previous session, basically a datastore but with tools. and everytime i leave the game i get this message in the output

“DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 3837598027-tools”

this is the script:

local Players = game.Players
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData1")
local function SaveData(plr)
	local toolsOwned = {}

	for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do

		table.insert(toolsOwned, toolInBackpack.Name)
	end

	local success, errormsg = pcall(function()

		toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
	end)
	if errormsg then warn(errormsg) end
end

Players.PlayerRemoving:Connect(SaveData)
game:BindToClose(function()
	for _, plr in ipairs(Players:GetPlayers()) do
		SaveData(plr)
	end
end)
2 Likes

Maybe add a task.wait(3) to the BindToClose function so that it has time to save. The rest of the script looks fine to me.

so it should look like this?

game:BindToClose(function()
	task.wait(3)
	for _, plr in ipairs(Players:GetPlayers()) do
		SaveData(plr)
	end
end)

No, put the task.wait() after the for loop so that the game has time to save it.

game:BindToClose(function()
	for _, plr in ipairs(Players:GetPlayers()) do
		SaveData(plr)
	end
	task.wait(3)
end)
game:BindToClose(function()
	for _, plr in ipairs(Players:GetPlayers()) do
		SaveData(plr)
		task.wait(3)
	end
end)

Oh alright, sry im bad with datastores.

1 Like

Well uhhh i still get that message in the output.

Oh wait, it might be because it is running the playerremoving and bindtoclose function at the same time. You are testing this with one player in the server, right?

uhhhh i dont know to be honest. but how would i fix that?

I’m not sure if this is the best method but you could just change the BindToClose function to this. The data should still save because the PlayerRemoving function is running

game:BindToClose(function()
	task.wait(3)
end)
1 Like

so the script should look like this?

local Players = game.Players
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData1")
local function SaveData(plr)
	local toolsOwned = {}

	for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do

		table.insert(toolsOwned, toolInBackpack.Name)
	end

	local success, errormsg = pcall(function()

		toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
	end)
	if errormsg then warn(errormsg) end
end

Players.PlayerRemoving:Connect(SaveData)
game:BindToClose(function()
	task.wait(3)
end)

Yes

30char.sfdhgnjkhtrgnjkhnjk;gfjhnkl;nhgjok;fednhgdf;jhkn

dang i just realized that the script by itself doesnt work. eh

What error is it giving you?

Edit: I was wrong, dont follow this:

original post

Also, you should change

for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do

to

for i, toolInBackpack in pairs(plr.StarterGear:GetChildren()) do

in case the player died or lost their tool.

no errors. it just doesn’t save, you dont have to help me ill use a free model anyway i suck.

How do you know it doesn’t save? Also can you add a print statement to the end of your pcall like this:

local success, errormsg = pcall(function()
		toolsDS:SetAsync(plr.UserId.."-tools", toolsOwned)
	end)
	if success then
		print("Saved data: "..toolsOwned)
	elseif errormsg then 
		warn(errormsg) 
	end

Sorry if the first sentence sounded obnoxious

Edit: i read your comment wrong

it doesn’t print anything.,.,.,.

That’s weird, your script looks fine. Do you have API services enabled for your game?

yeah i do, i also use leaderstats in my game.

I have no idea then. I guess you could try following a tutorial.