Hello, so I have a Leaderboard + Datastore system where the player has stats that can be changed, and saved. I'd like to make it clear that my method and script does work, but not all the time. I'm not fully experienced with all of DataStoreService's features.

Here's the exact issue I'd like to point out: When the player leaves, an error will occasionally pop up:

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.

This only happens if the game has auto-saved the stats recently. This doesn't make sense to me, as the limit for :SetAsync() should be 60 + the number of players x 10.

Here's the whole scrip [I believe the exact problem is in the .PlayerRemoving event]:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

local AutoSaveDelay = 15

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Oranges = Instance.new("IntValue")
	Oranges.Name = "Oranges"
	Oranges.Parent = leaderstats
	
	local Rebirths = Instance.new("IntValue")
	Rebirths.Name = "Rebirths"
	Rebirths.Parent = leaderstats
	
	local PlayerUserId = "Player_"..player.UserId
	
	-- Loading the Data here!
	
	local Data
	
	local Success, Error = pcall(function()
		Data = myDataStore:GetAsync(PlayerUserId)
	end)
	
	if Success then
		if Data then
			print("Data loaded!")
			Oranges.Value = Data.Oranges
			Rebirths.Value = Data.Rebirths
		else
			print("Error with loading! [Can't find Data]")
			print(Error)
		end	
	else
		print("Error with loading! [PCall failed!]")
		print(Error)
	end
	
	while wait(AutoSaveDelay) do
		local Data = {
			Oranges = player.leaderstats.Oranges.Value,
			Rebirths = player.leaderstats.Rebirths.Value,
		}
		
		local Success, Error = pcall(function()
			Data = myDataStore:SetAsync(PlayerUserId, Data)
		end)
		
		if Success then
			print("Data saved!")
		else
			print("Error with saving!")
			print(Error)
		end
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	
	local PlayerUserId = "Player_"..player.UserId
	
	local Data = {
		Oranges = player.leaderstats.Oranges.Value,
		Rebirths = player.leaderstats.Rebirths.Value,
	}
	
	local Success, Error = pcall(function()
		myDataStore:SetAsync(PlayerUserId, Data)
	end)
	
	if Success then
		print("Data saved!")
	else
		print("Error with saving!")
		print(Error)
	end
end)

1 comment

0

oof that looks a lot like mine sorry i couldn't help