Really weird issue with Data

So a few ppl in my game have been reporting they have no data, and it’s true, when I printed their data, it just returned nil, instead of giving them the default data shown here:
image
This error occurred when roblox servers were down and now their data is simply nil. I don’t wanna risk doing a nil check because then if theres another error in roblox’s system, it would cause a data wipe so what do I do?

3 Likes

If there’s an error in Roblox’s servers (and one that isn’t a request limit), you should kick everyone from the game saying “Roblox’s servers are down” or something to prevent further data losss.

Ok so that will prevent it from happening again but how do I make it so that ppl who got data wiped can start again because it doesn’t even give them default data its literally just nil even though the function runs

It’s not possible that it’s nil, since you already have a nil check. if not playerData then.

You need to add a longer cooldown to the task.wait() because if the pcall returns false it will jump straight into trying and probably failing again.
Also, currently the attempt value is too low, basically you try twice to get the players data before giving up.
You will also want to add an else to

if success then

If it has failed you can’t be sure if the player has data or not so might be safer to kick them rather than give them default data.

What would you recommend setting the value of the attempts and wait to?

Do you have the game:BindToClose() function as a shutdown-saver? (ofc you gotta do extra coding for that a bit)

Yeah over here, is there a better way to do it?:

game:BindToClose(function()--if game shuts down
	if not RunService:IsStudio() then
		print("Shutting down")
		for index, player in pairs(Players:GetPlayers()) do
			task.spawn(function()
				saveData(player)
			end)
		end
	else
		print("Shutting down inside studio")
	end
end)

It kinda depends on your player load setup but waiting 3seconds and trying 5 times would mean the player would only be waiting 15 seconds before either loading or getting kicked. Which seems reasonable to me. (I think session lock timeouts in some popular modules are a minute or more)

From my experience, you must GetAsync the data to ensure that it has been set correctly in BindToClose. Also remove the task.spawn and the pairs.

Cool GnomeCode Tutorial you got there my guy. Nonetheless, he made another tutorial and he did ipairs instead of pairs, try doing that.

I removed task.Spawn and the pairs but whats the difference between UpdateAsync and GetAsync? Also, how do I make it so those people with somehow nil data (I think it was because I made a mistake a while ago and then now thats their saved data), can actually play again whether they have their old data or just the default one because they can’t really do anything

You won’t need to know what UpdateAsync does in this case. If the person who has this supposed “nil data” has had correct data within 30 days, you can revert their data version using DataStore:ListVersionsAsync().

I’ve never really used this, any sample code you could provide?

There is a code sample provided in the documentation if you are interested.