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)
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?
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
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)
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