[ URGENT ] Major Issue Relating to Data Stores

Hello, everyone!

My game recently got featured on Roblox, and I’m a really worried about something. Currently, in any of the places except for 1 or 2, I’m getting “Exhausted DataStore” errors and I’m not entirely sure what to do to fix it. The data eventually loads but it takes it almost 10 minutes - something I’ve experienced only Roblox Studio.

Any help would be extremely helpful.

Screenshot:

Code for Datastore:

local stuff={
"ClanTag","StringValue","";
"ClanTagPreview","StringValue","";

}
local DS=game:GetService"DataStoreService":GetDataStore("SoldierId","global")

game:GetService"Players".PlayerAdded:Connect(function(p)
		
local leaderstats=p:WaitForChild("SoldierId",.3)or table.foreach({''},function(i)i=Instance.new("Folder",p)i.Name="SoldierId"return(i)end)

for x=1,#stuff,3 do
	
local save;delay(3,function()save=true;end)
local val=Instance.new(stuff[x+1])

	val.Name=stuff[x]

do local data=DS:GetAsync(p.UserId..stuff[x])
	val.Value=data and type(stuff[x+2])==type(data)and data or stuff[x+2]end
	val.Parent=leaderstats
	
val.Changed:Connect(function()if save then
	save=false;DS:SetAsync(p.UserId..val.Name,val.Value)
	
	delay(6,function()save=true;end)	
	end
end)


	end
end)

The code you posted is not readable. Please format and indent it correctly and someone may be able to help you out.

Look here for tips on indenting/formatting:
http://lua-users.org/wiki/LuaStyleGuide

This one is specifically aimed at Roblox-Lua projects:
https://roblox.github.io/lua-style-guide/

3 Likes

My apologies - the post has been updated with indented code!

It seems you are saving and loading data with the intent that it never fails. By this, I mean you aren’t checking if the datastores failed to save or load the user’s data. Because of this, the user’s data doesn’t load and when they leave, a blank data template is saved, or their data isn’t saved period. I also recommend checking to see if a user’s data has successfully been loaded before you attempt to save their data.

Loading the user’s data
LoadDS

Check in the save function so that we don’t save over a user that hasn’t loaded
NotLoad

And finally making sure our data saves if it passed the load test
DataSave

3 Likes

The problem could be that you’re saving on Changed. Of course, you should have error handling and a retry system in place for when requests do fail, but you should also prevent issues where you can. I’m not sure how often Changed fires, but if players are able to change their ClanTag or ClanTagPreview rapidly, they will quickly exhaust your available requests (hence, the descriptive warning). In this case, you would need to only save it every couple of minutes, on PlayerRemoving, or when the game shuts down.

3 Likes

That is actually something I didn’t think about. I recently added in the clan tag system and it updates everytime a player types in a box.

Just to be on the safe side, will that cause my other data stores to fail?

If so, that’d be a pretty easy fix to do!

Yes, all DataStores use the same pool of requests. If one uses up all available requests, the others will fail as well.

2 Likes

Usually data stores fail because you exhausted the request limit. On rare occasions, they could just be down.

Oh my god.

That’s really simple to fix now.

I’m going to add in the PCall functions as well.

Wish I could accept both of your guy’s answers.

Quick question: Can multiple datastore scripts that go to different data stores have any impact on them?

The reason why you are getting these warnings is because either:

  1. You are trying to write (update/set/remove/increment) a key that was recently written to within 6 seconds.
  2. You are out of budget.

This is global to the server. If one script tries to write a key and another tries to write the key too, one of them will throttle because you are violating the 6 second write rule. The same goes for budgets, budgets are shared for all scripts on a server.

You can read more about datastores here:
https://devforum.roblox.com/t/details-on-datastoreservice-for-advanced-developers/175804

To solve your issues, you need to make sure there is no way you can accidentally attempt writing a key again within 6 seconds, and that you can’t run out of budget. A simple way to do this is not to listen to changed-like signals / update whenever the player changes something, but instead save on a time interval and when players leave the server.

1 Like