#DataStore request was added to queue

17 messages · Page 1 of 1 (latest)

left jacinth
#

So I have my datastore but for some reason it always gives this warning when i leave: 15:38:10.218 DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = id_1263163446 - Studio, how do i fix this?

#

-- Function to save player data to the DataStore
local function savePlayerData(player)
    local plrkey = "id_" .. player.UserId

    local savevalue = player.leaderstats["Jump Height"]
    local savevalue2 = player.leaderstats.Wins
    local savevalue3 = player.Gravity

    local NumbersForSaving = {
        savevalue.Value,
        savevalue2.Value,
        savevalue3.Value,
    }

    DS:SetAsync(plrkey, NumbersForSaving)
end

game.Players.PlayerAdded:Connect(function(plr)
    wait()

    -- Load player data from the DataStore
    local plrkey = "id_" .. plr.UserId
    local GetSaved = DS:GetAsync(plrkey)

    if GetSaved then
        local savevalue = plr.leaderstats["Jump Height"]
        local savevalue2 = plr.leaderstats.Wins
        local savevalue3 = plr.Gravity

        -- Set values from the DataStore
        savevalue.Value = GetSaved[1]
        savevalue2.Value = GetSaved[2]
        savevalue3.Value = GetSaved[3]
    else
        local savevalue = Instance.new("NumberValue", plr)
        savevalue.Name = "Jump Height"
        local savevalue2 = Instance.new("IntValue", plr)
        savevalue2.Name = "Wins"
        local savevalue3 = Instance.new("NumberValue", plr)
        savevalue3.Name = "Gravity"
    end
    wait(1)
    if plr["Gravity"].Value == 0 then
        plr["Gravity"].Value = 196.2
    end

    if plr.leaderstats["Jump Height"].Value > 0 then
        repeat
            wait()
        until plr.Character
        wait(0.5)
        plr.Character.Humanoid.JumpHeight = plr.leaderstats["Jump Height"].Value
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    savePlayerData(plr)
    print("Left Successfully")
end)

game:BindToClose(function()
    for _, plr in pairs(game.Players:GetPlayers()) do
        savePlayerData(plr)
        plr:Kick()
        print("Left Successfully")
    end
end)```
#

can anyone tell what is wrong?

wooden sun
#

@left jacinth i recommend adding some error handling.

#

error handling to the SetAsync and GetAsync methods

#

You can use pcall to call the SetAsync and GetAsync

left jacinth
#

Tried it but i still get the same warning

plucky maple
#

The warning message you're seeing is related to the rate at which you're sending requests to the DataStore. To fix this, you can implement rate limiting by introducing a delay between each request.

Here's an updated version of your script that includes rate limiting:

#

local DS = game:GetService("DataStoreService"):GetDataStore("DataStoreName-1")
local MAX_REQUESTS_PER_MINUTE = 10 -- Adjust this value as needed

local function savePlayerData(player)
local plrkey = "id_" .. player.UserId

local savevalue = player.leaderstats["Jump Height"]
local savevalue2 = player.leaderstats.Wins
local savevalue3 = player.Gravity

local NumbersForSaving = {
    savevalue.Value,
    savevalue2.Value,
    savevalue3.Value,
}

DS:SetAsync(plrkey, NumbersForSaving)

end

game.Players.PlayerAdded:Connect(function(plr)
wait()

local plrkey = "id_" .. plr.UserId
local GetSaved = DS:GetAsync(plrkey)

if GetSaved then
    local savevalue = plr.leaderstats["Jump Height"]
    local savevalue2 = plr.leaderstats.Wins
    local savevalue3 = plr.Gravity

    savevalue.Value = GetSaved[1]
    savevalue2.Value = GetSaved[2]
    savevalue3.Value = GetSaved[3]
else
    local savevalue = Instance.new("NumberValue", plr)
    savevalue.Name = "Jump Height"
    local savevalue2 = Instance.new("IntValue", plr)
    savevalue2.Name = "Wins"
    local savevalue3 = Instance.new("NumberValue", plr)
    savevalue3.Name = "Gravity"
end
wait(1)
if plr["Gravity"].Value == 0 then
    plr["Gravity"].Value = 196.2
end

if plr.leaderstats["Jump Height"].Value > 0 then
    repeat
        wait()
    until plr.Character
    wait(0.5)
    plr.Character.Humanoid.JumpHeight = plr.leaderstats["Jump Height"].Value
end

end)

#

game.Players.PlayerRemoving:Connect(function(plr)
savePlayerData(plr)
print("Left Successfully")
end)

game:BindToClose(function()
local players = game.Players:GetPlayers()
local numPlayers = #players
local requestsSent = 0

for _, plr in ipairs(players) do
    savePlayerData(plr)
    plr:Kick()
    requestsSent = requestsSent + 1

    if requestsSent >= numPlayers or requestsSent >= MAX_REQUESTS_PER_MINUTE then
        break
    end
end

print("Left Successfully")

end)

#

@left jacinth

left jacinth
#

tysm i will try this rn

#

Hm weird it seems i still have the warning

#

really weird

plucky maple
#

Ignore it my script is 100% right

#

Also tag me if u wanna message back

ashen plaza