Getting Data queue Error when players join or leave at the same time causing very slow data loading times

So if players join at the same time an error comes up saying data queue, for a very long time until the player actual loads in the data.

--Services--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")

--Shortcuts--
local Folder = ReplicatedStorage:WaitForChild("DataStore")

--Variables--


--functions--
local function GetDS(Value, Player)
	local DS = DataStoreService:GetDataStore(Value.Name)
	local Data;
		
	local DataFetchSuccess, ErrorMessage = pcall(function()
		Data = DS:GetAsync(tostring(Player.UserId))
	end)
		
	if DataFetchSuccess then
		if Data == nil and Value.Name == "DeafultKnife" or Value.Name == "DeafultFlashlight" or Value.Name == "Clown" then
			Value.Value = true
		elseif Data == nil and Value.Name == "Skin" then
			Value.Value = "Clown"
		elseif Data == nil and Value.ClassName == "StringValue" then
			Value.Value = ("Deafult"..Value.Name)
		elseif Data == nil and Value.ClassName == "BoolValue" then
			Value.Value = false
		elseif Data == nil and Value.ClassName == "NumberValue" then
			Value.Value = 0
		else
			Value.Value = Data
		end
	end
end

local function SetDS(Value, Player)
	if Player.CanSaveData.Value == false then return end
	local DS = DataStoreService:GetDataStore(Value.Name)
	local Data = DS:GetAsync(tostring(Player.UserId))
	
	if Data ~= Value.Value then
		local DataWriteSuccess, ErrorMessage = pcall(function()
			DS:SetAsync(tostring(Player.UserId),Value.Value)
		end)
		
		if not DataWriteSuccess then
			local Retry = 0
		
			while Retry < 6 do
				wait(60)
				local Succeded, Error = pcall(function()
					DS:SetAsync(tostring(Player.UserId),Value.Value)	
				end)
				if Succeded then break end
				Retry = Retry + 1
			end
		end
	end
end

local function CheckChildren(Key, Children, Player)
	for i = 1, #Children do
		if Children[i].ClassName == "Folder" then
			local C = Children[i]:GetChildren()
			if C then
				CheckChildren(Key, C, Player)
			end
		else
			if Key == "GetDS" then
				GetDS(Children[i], Player)
			else
				SetDS(Children[i], Player)
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	
	--//Loading DataStores\\--
	local Clone = Folder:Clone()
	Clone.Parent = Player
	local FolderChildren = Clone:GetChildren()
	CheckChildren("GetDS", FolderChildren, Player)
	
	-------------------
	print("DataStore Loaded")
	--CanSaveValue--
	local CanSave = Instance.new("BoolValue",Player)
	CanSave.Name = "CanSaveData"
	CanSave.Value = true
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Clone = Player:FindFirstChild("DataStore")
	if Clone then
		local CloneChildren = Clone:GetChildren()
		CheckChildren("SetDS", CloneChildren, Player)
		print("Inventory Saved")
	end
end)
1 Like

What does CheckChildren() do?

local function CheckChildren(Key, Children, Player)
	for i = 1, #Children do
		if Children[i].ClassName == "Folder" then
			local C = Children[i]:GetChildren()
			if C then
				CheckChildren(Key, C, Player)
			end
		else
			if Key == "GetDS" then
				GetDS(Children[i], Player)
			else
				SetDS(Children[i], Player)
			end
		end
	end
end

yes i have folders inside of folders inside of folders

Alright got you. I just re-read the script just to fully understand it. It’s very complicated and kind of unorganized what you’re trying to do. But to answer your question, that message will sometimes appear when even only 1 person joins in [atleast I’ve experienced that]. It’s fine since you’ve used pcall() so if it errors, then it won’t load the data. Just make sure you don’t save the data in the case that it fails.

I have experienced this in the studio output too.

For some reason Roblox studios in server data store limits are different to actual game servers. As long as these don’t show up in-game, you’re fine.

For another check, you could calculate how many requests your script makes per minute to line it up.

1 Like

yea it shows in game sadly. I think its because its running the data store when players join at the same for both players causing the queue,how would i wait for each person to save and not at the same time.

You shouldn’t have a throttling issue if you’re only saving two people’s data.

Is there a reason why you can’t save player data with 1 datastore? You should avoid using a different datastore for every single data field.

i am saving the player with only 1 datastore?

Your script is using a different datastore for every value.

local function CheckChildren(Key, Children, Player)
	for i = 1, #Children do
		if Children[i].ClassName == "Folder" then
			local C = Children[i]:GetChildren()
			if C then
				CheckChildren(Key, C, Player)
			end
		else
			if Key == "GetDS" then
				GetDS(Children[i], Player)
			else
				SetDS(Children[i], Player)
			end
		end
	end
end

You need to save all values to a single datastore if you want to avoid going over the limit.