Datastore Requests Error

Hello DevForum once again!
I have a DataStore system that is supposed to increment someones data every 60 seconds. For some reason my logs are being spammed with requests. I sent the errors to a webhook and these were the errors I was getting. Keep in mind my webhook is being spammed as we speak with these errors.

Minutes DataStore Error: Failed to apply minutes to Wellingsworth. Error: 303: IncrementAsync request dropped. Request was throttled, but throttled request queue was full…

Minutes DataStore Error: Failed to apply minutes to Sock_master12. Error: 502: API Services rejected request with error. HTTP 429.

Output in game:

Any help would be appreciated, thanks!
Player data is on the line.

local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")
local HttpService = game:GetService("HttpService")
local MinuteStore = DataStoreService:GetOrderedDataStore("minuteDataStore")
local CashStore = DataStoreService:GetOrderedDataStore("cashDataStore")
local Webhook = "discord"
																																																																							
game.Players.PlayerAdded:Connect(function(Player)
	local Amount = 1
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = Player
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	local MinutesPlayed = Instance.new("IntValue")
	MinutesPlayed.Name = "MinutesPlayed"
	MinutesPlayed.Parent = Leaderstats
	
	local GMS, GMV = pcall(function()
		return MinuteStore:GetAsync(Player.UserId)
	end)
	local GCS, GCV = pcall(function()
		return CashStore:GetAsync(Player.UserId)
	end)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 9117814) then
		Amount = Amount+1
	end
	
	if GMS then
		MinutesPlayed.Value = GMV
		while true do
			wait(60)
			local IMS, IMV = pcall(function()
				MinuteStore:IncrementAsync(Player.UserId, Amount)
			end)
			wait()
			local RGMS, RGMV = pcall(function()
				return MinuteStore:GetAsync(Player.UserId)
			end)
			if IMS and RGMS then
				MinutesPlayed.Value = RGMV
			elseif not IMS and not RGMS then
				local Data = {
					["content"] = ("**Minutes DataStore Error:**\nFailed to apply minutes to "..Player.Name..". Error: "..IMV..".")
				}
				Data = HttpService:JSONEncode(Data)
				HttpService:PostAsync(Webhook, Data)
			end
		end
	elseif not GMS then
		local Data = {
			["content"] = ("**Minutes DataStore Error:**\nFailed to apply minutes to "..Player.Name..". Error: "..GMV..".")
		}
		Data = HttpService:JSONEncode(Data)
		HttpService:PostAsync(Webhook, Data)
	end
	
	if GCS then
		MinutesPlayed.Value = GMV
		while true do
			wait(60)
			local ICS, ICV = pcall(function()
				CashStore:IncrementAsync(Player.UserId, 1)
			end)
			wait()
			local RGCS, RGCV = pcall(function()
				return CashStore:GetAsync(Player.UserId)
			end)
			if ICS and RGCS then
				Cash.Value = ICV
			elseif not ICS and not RGCS then
				local Data = {
					["content"] = ("**Cash DataStore Error:**\nFailed to apply cash to "..Player.Name..". Error: "..ICV..".")
				}
				Data = HttpService:JSONEncode(Data)
				HttpService:PostAsync(Webhook, Data)
			end
		end
	elseif not GCS then
		local Data = {
			["content"] = ("**Cash DataStore Error:**\nFailed to get info from DataStore. Error: "..GCV..".")
		}
		Data = HttpService:JSONEncode(Data)
		HttpService:PostAsync(Webhook, Data)
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if string.sub(Message, 1, 6) == "/medit" then
			if Player.UserId == 152577902 or Player.UserId == 154458656 or Player.UserId == 61526700 then
				local Args = string.split(Message, " ")
				local Target = tonumber(Args[2])
				local Amount = tonumber(Args[3])
				local GMS, GMR = pcall(function()
					return MinuteStore:GetAsync(Target)
				end)
				if GMS then
					print(Target)
					local Success, Result = pcall(function()
						MinuteStore:SetAsync(Target, Amount)
					end)
					if Success then
						local Data = {
							["content"] = ("**"..Player.Name.."("..Player.UserId..")** Has edited: **"..Args[2].."**'s level. Updated level to: **"..Args[3].."**.")
						}
						Data = HttpService:JSONEncode(Data)
						HttpService:PostAsync(Webhook, Data)
					elseif not Success then
						local Data = {
							["content"] = ("**Level Refund Error: **\n"..Result..".")
						}
						Data = HttpService:JSONEncode(Data)
						HttpService:PostAsync(Webhook, Data)
					end
				elseif not GMS then
					local Data = {
						["content"] = ("**Level Refund Error: **\nFailed to load data.")
					}
					Data = HttpService:JSONEncode(Data)
					HttpService:PostAsync(Webhook, Data)
				end
			end
		elseif string.sub(Message, 1, 6) == "/cedit" then
			local ps, pr = pcall(function()
				if Player.UserId == 152577902 or Player.UserId == 154458656 or Player.UserId == 61526700 then
					local Args = string.split(Message, " ")
					local Target = tonumber(Args[2])
					local Amount = tonumber(Args[3])
					local GCS, GCR = pcall(function()
						return CashStore:GetAsync(Target)
					end)
					if GCS then
						print(Target)
						local Success, Result = pcall(function()
							CashStore:SetAsync(Target, Amount)
						end)
						if Success then
							local Data = {
								["content"] = ("**"..Player.Name.."("..Player.UserId..")** Has edited: **"..Args[2].."**'s cash. Updated cash to: **"..Args[3].."**.")
							}
							Data = HttpService:JSONEncode(Data)
							HttpService:PostAsync(Webhook, Data)
						elseif not Success then
							local Data = {
								["content"] = ("**Cash Refund Error: **\n"..Result..".")
							}
							Data = HttpService:JSONEncode(Data)
							HttpService:PostAsync(Webhook, Data)
						end
					elseif not GCS then
						local Data = {
							["content"] = ("**Cash Refund Error: **\nFailed to load data.")
						}
						Data = HttpService:JSONEncode(Data)
						HttpService:PostAsync(Webhook, Data)
					end
				end
			end)
		end
	end)
end)

This means that you’re making too many requests. Just make lower requests.

Go to Game Settings > Security > API Services and enable them.

1 Like

How would I do that if I increment someones data every 60 seconds?
API’s are already on.

Your best way of accomplishing this without throttles and drops is to create and increment an Int Value by the amount. Upon the player leaving is when you would store it.

I did originally do this but I was losing player data. Also from what I read up, saving data every time it changes was the way forward.