Assistance with DataStores

Occasionally when I test-play my game in Studio, my data is reset back to 0… I also get this warning:

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

I have exactly no clue on what this means and I am curious if this is the culprit to my data loss. Any ideas/clues?

How are you saving or loading your data? Seems like your passing the request limit.

I am using a DataStore… could you by any chance give me more of an explanation?

Yeah I guess I wasn’t too specific. Do you have like a loop running which saves data every set amount of seconds?

No, I have a table that holds all of the datastore values I want to save

Would you mind sending some of the script because I can’t really review it otherwise?

Sure:

local DS = game:GetService("DataStoreService"):GetDataStore("WWEDataStoreGet")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local savevalue = plr.leaderstats.Coins
	local savevalue2 = plr.leaderstats.Bucks
	local savevalue3 = plr.Equipped
	local savevalue4 = plr.CoinsBoost
	local savevalue5 = plr.BucksBoost
	local savevalue6 = plr.leaderstats.Talent
	local savevalue7 = plr.JoinedGroup
	local savevalue8 = plr.FaveSuperstar1
	local savevalue9 = plr.League
	
	local GetSaved = DS:GetAsync(plrkey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
		savevalue2.Value = GetSaved[2]
		savevalue3.Value = GetSaved[3]
		savevalue4.Value = GetSaved[4]
		savevalue5.Value = GetSaved[5]
		savevalue6.Value = GetSaved[6]
		savevalue7.Value = GetSaved[7]
		savevalue8.Value = GetSaved[8]
		savevalue9.Value = GetSaved[9]
		
	else
		local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value, savevalue4.Value, savevalue5.Value, savevalue6.Value, savevalue7.Value, savevalue8.Value, savevalue9.Value}
		DS:GetAsync(plrkey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Coins.Value, plr.leaderstats.Bucks.Value, plr.Equipped.Value, plr.CoinsBoost.Value, plr.BucksBoost.Value, plr.leaderstats.Talent.Value, plr.JoinedGroup.Value, plr.FaveSuperstar1.Value, plr.League.Value})
end)

Could you try a print to see if it’s getting the data or not getting it at all.

Also, i’d do plr.UserId instead of plr.userId but I doubt thats the issue

Where should I put the print in the script?

so after the local GetSaved, on the next line you would want to do

for i,v in pairs(GetSaved) do
print(i,v)
end

And if you see a list of saved data then it means your saving works else it’s not finding any data.

Here is what I got:

08:11:54.500 1 711 - Server - DataStore:18
08:11:54.501 2 46 - Server - DataStore:18
08:11:54.501 3 - Server - DataStore:18
08:11:54.501 4 0 - Server - DataStore:18
08:11:54.501 5 0 - Server - DataStore:18
08:11:54.502 6 0 - Server - DataStore:18
08:11:54.502 7 true - Server - DataStore:18
08:11:54.502 8 - Server - DataStore:18
08:11:54.503 9 1 - Server - DataStore:18

is this it?

Yeah seems like you do have data, this may possibly be something with the loading.

I believe that the GetSaved returns nil so then it does the else statement and sends a GetAsync request again. Now you have sent 2 GetAsync requests in a split second, which is causing that error.

It says something about holding too many data store requests… could this mean I have too much of it?

What i’d recommend you to do is replace your loading with this-

local data;
local success,fail = pcall(function()
      data = DS:GetAsync(plrkey) or {} --This table should contain the beggining stats if player has no data
end)

if success then
		savevalue.Value = data[1]
		savevalue2.Value = data[2]
		savevalue3.Value = data[3]
		savevalue4.Value = data[4]
		savevalue5.Value = data[5]
		savevalue6.Value = data[6]
		savevalue7.Value = data[7]
		savevalue8.Value = data[8]
		savevalue9.Value = data[9]
else
       print("Failed to load data",fail)
end

I am still getting the error when I changed it…

Can you show me your new script

Will do:

local DS = game:GetService("DataStoreService"):GetDataStore("WWEDataStoreGet")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local savevalue = plr.leaderstats.Coins
	local savevalue2 = plr.leaderstats.Bucks
	local savevalue3 = plr.Equipped
	local savevalue4 = plr.CoinsBoost
	local savevalue5 = plr.BucksBoost
	local savevalue6 = plr.leaderstats.Talent
	local savevalue7 = plr.JoinedGroup
	local savevalue8 = plr.FaveSuperstar1
	local savevalue9 = plr.League
	
	local data;
	
	local success, fail = pcall(function()
		
		data = DS:GetAsync(plrkey) or {}
		
	end)
	
	if success then
		savevalue.Value = data[1]
		savevalue2.Value = data[2]
		savevalue3.Value = data[3]
		savevalue4.Value = data[4]
		savevalue5.Value = data[5]
		savevalue6.Value = data[6]
		savevalue7.Value = data[7]
		savevalue8.Value = data[8]
		savevalue9.Value = data[9]
		
	else
		
		local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value, savevalue4.Value, savevalue5.Value, savevalue6.Value, savevalue7.Value, savevalue8.Value, savevalue9.Value}
		DS:GetAsync(plrkey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Coins.Value, plr.leaderstats.Bucks.Value, plr.Equipped.Value, plr.CoinsBoost.Value, plr.BucksBoost.Value, plr.leaderstats.Talent.Value, plr.JoinedGroup.Value, plr.FaveSuperstar1.Value, plr.League.Value})
	print("Saved data")
end)

After the else, you need to get rid of it because that’s calling another GetAsync() too fast. The time allowed between 2 requests is 5 seconds therefore it’s throttling your request.

Also that’s if it errors therefore I would print out the error if it gets there.

Do I need to get rid of the local part or the GetAsync part?