Datastore request added to queue (Datastore 2)

When I join the game with multiple players, the Datastore request added to queue warning keeps showing up on server logs and it takes a few minutes for everyone’s data to load in. Could you guys check my code and help me?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local DataStore2 = require(script:WaitForChild("DataStore2"))
local LevelModule = require(script:WaitForChild("Level"))

local DataVars = {
	--General
	["Cash"] = {"NumberValue", 100},
	["Hunger"] = {"NumberValue", 100},
	["Level"] = {"NumberValue", 1},
	["XP"] = {"NumberValue", 0},
	["CO2"] = {"NumberValue", 0},
	--Phone
	["PhoneR"] = {"NumberValue", 87},
	["PhoneG"] = {"NumberValue", 88},
	["PhoneB"] = {"NumberValue", 87},
	--Cars
	["Mercedes-Benz S Class"] = {"BoolValue", false},
	["Rolls-Royce Phantom"] = {"BoolValue", false},
	["Honda Civic Hatchback"] = {"BoolValue", false},
	["Tesla Cybertruck"] = {"BoolValue", false},
	["Tesla Roadster"] = {"BoolValue", false},
	["Toyota Prius"] = {"BoolValue", false},
	["Hyundai Avante Sedan"] = {"BoolValue", false},
	["Lamborghini Aventador SV"] = {"BoolValue", false},
}


function addPlayer(player)
	local DataFolder = Instance.new("Folder", player)
	DataFolder.Name = "Data"
	local CarFolder = Instance.new("Folder", DataFolder)
	CarFolder.Name = "Cars"
	
	--Loop to make rep amounts
	for key, defaultval in pairs(DataVars) do
	wait()
	local keystore = DataStore2(key, player)
	
	local RepAmt
	if defaultval[1] == "BoolValue" then
		RepAmt = Instance.new(defaultval[1], CarFolder)
		RepAmt.Name = key
	else
		RepAmt = Instance.new(defaultval[1], DataFolder)
		RepAmt.Name = key
	end
	
	local function UpdateRepAmt(updatedValue)
		RepAmt.Value = keystore:Get(updatedValue)
	end
	
	UpdateRepAmt(defaultval[2])
	keystore:OnUpdate(UpdateRepAmt)
	print(key.." loaded")
	end
	
	
end



for _,player in pairs(Players:GetPlayers())do
    addPlayer(player)
end

Players.PlayerAdded:connect(addPlayer)

1 Like

You might want to put a wait() in the for loop for DataVars and CarVars to allow for congestion.

1 Like

Thanks! Just rewrote the datastore entirely

If you store the data in the player, can’t they just modify it to give themselves whatever they want?

The values stored under player is only the replicated value, if they change the value on their end it will just be reverted back to the server value.

Oh, okay. Could you explain why you use a value in the player? A bit confused about this lol

It’s just a replicated amount to be stored in the player so I can access it client side without requesting from datastore

You might want to put a wait() in the for loop for DataVars and CarVars to allow for congestion.

This isn’t the issue, you are most likely surpassing the DataStore:GetAsync() limits, you should always use the DataStore2.Combine method as stated on the page.

Oh, so I just do DataStore2.Combine(“Test1”, key) ?
not sure

That is exactly what you do. For some documentation on why you are getting this error and about combined datastores visit this page:
https://kampfkarren.github.io/Roblox/guide/gotchas/

Whenever you add new keys always combine it to the master key. This will make all your data save under one big table internally.


Edit:

local LevelModule = require(script:WaitForChild("Level"))

I noticed you also get an infinite yield warning from this line. This could be another cause for your problem. Make sure you are referencing the level module correctly.

2 Likes

Combines all the keys under keysToCombine under the masterKey . Internally, will save all data under those keys into the masterKey as one large dictionary.

An example:

DataStore2.Combine("PlayerData", "Cash", "Hunger", "Level", "XP", "CO2")
                  --MasterKey     KeysToCombine

You may want to read the guide from the github page.

2 Likes

thanks guys

no the level module is referenced correctly the game just takes long to load lol

1 Like