Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I fix this "DataStore was added to queue error"?

Asked by 3 years ago

In my game, I keep getting this error that says "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests." I've tried many things but none of them seem to work. Is there anyway to fix this? I really need help. Thanks.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData", 1)

local function SavePlayerData(player)

    local success,errormsg = pcall(function()

        local SaveData = {}

        for i,stats in pairs(player.leaderstats:GetChildren()) do

            SaveData[stats.Name] = stats.Value
        end 
        SaveDataStore:SetAsync(player.UserId,SaveData)
    end)

    if not success then
        return errormsg
    end         
end 



Players.PlayerAdded:Connect(function(player)

    local Stats = Instance.new("Folder")
    Stats.Name = "leaderstats"
    Stats.Parent = player

    local Stage = Instance.new("NumberValue")
    Stage.Name = "Stage"
    Stage.Parent = Stats
    Stage.Value = 0

    local Data = SaveDataStore:GetAsync(player.UserId)

    if Data then

        print(Data.Stage)

        for i,stats in pairs(Stats:GetChildren()) do

            stats.Value = Data[stats.Name]      
        end         
    else        
        print(player.Name .. " has no data.")           
    end


    player.CharacterAdded:Connect(function(character)

        local Humanoid = character:WaitForChild("Humanoid")
        local Torso = character:WaitForChild("HumanoidRootPart")

        wait()

        if Torso and Humanoid then
            if Stage.Value ~= 0 then

                local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
                Torso.CFrame = StagePart.CFrame + Vector3.new(0,1,0)                    
            end 
        end 
    end)        
end)


Players.PlayerRemoving:Connect(function(player)

    local errormsg = SavePlayerData(player)

    if errormsg then    
        warn(errormsg)      
    end 
end)

game:BindToClose(function()
    for i,player in pairs(Players:GetPlayers()) do  

        local errormsg = SavePlayerData(player)
        if errormsg then
            warn(errormsg)
        end         
    end
    wait(2) 
end)

0
can you accept the answer @NotANinja_9210? R_LabradorRetriever 198 — 3y
0
i did it NotANinja_9210 7 — 3y
0
kk R_LabradorRetriever 198 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

The problem is that you are saving data way too often.

https://developer.roblox.com/en-us/articles/Datastore-Errors

game:BindToClose(function()
   for i,player in pairs(Players:GetPlayers()) do  

        local errormsg = SavePlayerData(player)
        if errormsg then
            warn(errormsg)
        end        
    end
    wait(2)
end)

Don't do an auto save like that, saving when players leave or join is enough. Delete lines 78-87 (the lines above) completely and your problem is gone!

0
Thank you so much!! The error is not popping up anymore! NotANinja_9210 7 — 3y
Ad

Answer this question