DataStore exceeding limit after 1 attempt?

Why is my datastore exceeding limits after only trying to save once? I’m a bit confused.

local _DATASTORE_SEVER = game:GetService("DataStoreService"):GetDataStore("____SEERRRVVVEEREEEERR_DDDAAAATTTTAAAAAAA_______")

["SAVE"] = function(information)
	--TODO: Try to save the DATA_FOLDER and all of the server data needed?
	local SAVE_Attempts, Max_SAVE_Attempts = 0, math.random(5,10) --Used to determine how many times the function attempted to run, Used to determine how many times we will allow that function to run.


	local function SAVE()
		print("attempting")
		_DATASTORE_SEVER:SetAsync(information.Key, information.OBJ) --Attempt to save the info.
		game.Worskapcccee = 3 --ERROR (on purpose.)
	end

	local Save__DATA, _message; --Used to determine if the function was a success or not.
	repeat --Repeat
		task.wait() --wait

		print(SAVE_Attempts)
		SAVE_Attempts += 1 --add the attempts up by 1 so we know how many times the function is running
		Save__DATA, _message = pcall(function()
			SAVE() --Run the function. Attempt to load our data.
		end)

		if not Save__DATA == true then warn("[".. script.Name .. "]: Failed to save server data - ".. _message) wait(math.random(3,5)) end --IF the function was not a success then, wait and retry.

	until SAVE_Attempts > Max_SAVE_Attempts or Save__DATA == true --Until the function has exceeded the attempt limit or the function was a SUCCESS!

	if Save__DATA == true then
		print("[".. script.Name .. "] '" .. information.Key .. "' was just saved -", information.OBJ)
	end

	return Save__DATA;
	--Return true or false based on if the data needed was loaded succesfully or not.
end,

This code essentially does the same thing:

local _DATASTORE_SEVER = game:GetService("DataStoreService"):GetDataStore("____SEERRRVVVEEREEEERR_DDDAAAATTTTAAAAAAA_______")

for i = 1, 5 do
	task.wait(2)
	_DATASTORE_SEVER:SetAsync("TEST", 8)
	print("Saved", i)
end

For those of you that are too overwhelmed for the original code.

How can I check and make sure dataStore saves while also not throttling?

wrap it in a coroutine function and that should fix it

Is it possible to get an example of how I can use that in my code? I don’t have a lot of experience with coroutine functions

When writing to the same key, there’s a limitation in place as to how frequently that can execute. Roblox handles throttling for you, so it won’t cause your script to break. However, you should wait at least 6 seconds (per documentation) before calling SetAsync again on the same key.

1 Like
local _DATASTORE_SEVER = game:GetService("DataStoreService"):GetDataStore("____SEERRRVVVEEREEEERR_DDDAAAATTTTAAAAAAA_______")

for i = 1, 5 do
	task.wait(5)
    coroutine.wrap(function()
          _DATASTORE_SEVER:SetAsync("TEST", 8)
    end)
	print("Saved", i)
end