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

DataStore request was added to queue.?

Asked by
Yukogan 72
4 years ago
Edited 4 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

Hi, I am making a game with a daily reward system. It is constantly saying: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 792800740

I had two scripts that says GetDataStore, so I tried to make 1 script, with 1 GetDataStore, but it didn't worked...

Please help, someone :(

here is the code:

local DataStore = game:GetService("DataStoreService"):GetDataStore("PointLeaderStatsSaverKnobbyObby")

game.Players.PlayerAdded:Connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local currency = Instance.new("IntValue", folder)
    currency.Name = "Points"
    currency.Value = DataStore:GetAsync(plr.UserId) or 0
    currency.Changed:Connect(function()
        DataStore:SetAsync(plr.UserId, currency.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    DataStore:SetAsync(plr.UserId, plr.leaderstats.Points.Value)
end)

local hourWait = 24

local possibleRewards = {10,15,10,10,10,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,10,10,15,15,500}
game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = player:WaitForChild("leaderstats")

    local timeNow = os.time()

    local data

    pcall(function()
        data = DataStore:GetAsync(player.UserId.."-dailyRewards")
        print("Getting Data")
    end)

    if data ~= nil then
        -- Returning player to the game

        local timeSinceLastClaim = timeNow - data -- Number in sec since the last reward was claimed

        print("Time since last claim "..timeSinceLastClaim)

        if (timeSinceLastClaim / 3600) >= hourWait then
            -- They are eligible for a reward
            local reward = possibleRewards[math.random(1,#possibleRewards)]
            game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
            local connection
            connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
                if triggeringPlayer == player then
                    print("Reward Claimed")
                    player.leaderstats.Points.Value = player.leaderstats.Points.Value + reward
                    DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
                    connection:Disconnect()
                end
            end)
        else
            print("Player is uneligible right now")
        end

    else
        -- New player
        print("New Player")

        local reward = possibleRewards[math.random(1,#possibleRewards)]
        game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
        local connection
        connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
            if triggeringPlayer == player then
                print("Reward Claimed")
                player.leaderstats.Points.Value = player.leaderstats.Points.Value + reward
                DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
                connection:Disconnect()
            end
        end)
    end
end)

Ps: If my English is bad, I am from another country.

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

You may be constantly looping through and referencing datastore, this causes an insane amount of requests which causes this error.

0
I can't find any loop. I've added the code. Thanks for your answer! Yukogan 72 — 4y
0
Your error is most likely in lines 9 and 10, you're setting the datastore every single time the change function is called, that can cause a ton of requests depending on how often it's changed Robowon1 323 — 4y
0
Do you know how I can save the player's leaderstats, but without the error? Yukogan 72 — 4y
0
I would just set it when the player is removing rather than every time it changes Robowon1 323 — 4y
0
Ok! Thank you very much!! :) Yukogan 72 — 4y
Ad

Answer this question