Datastore request was added to the queue

(Also to clarify: i tried other solutions but didn’t work)

Hi, so I’m getting this warning from the topic of course, So how do I fix this, bc when someone invokes this function it gets a setasync throttled error.

Also I’m doing a settings thing so that’s why I’m using Remote Function

Client Script

Client script:

local Config = script.Parent.Parent:WaitForChild("Config")
local GetSettings = script.Parent.Settings:InvokeServer("GetData", Config.Test)
local Settings = script.Parent.Settings
local debounce = false

local function sendValue()
	Settings:InvokeServer("UpdateData", Config.Test)
end

local function updateValue()
	Config.Test.Value = GetSettings
	print(GetSettings)
end




Config.Test:GetPropertyChangedSignal("Value"):Connect(sendValue)
script.Parent.Toggle.Activated:Connect(function()
	print("Click")
	if Config.Test.Value == false then
		sendValue()
		print(Config.Test.Value)
		Config.Test.Value = true
		script.Parent.Toggle.Text = "On"
	elseif Config.Test.Value == true then
		sendValue()
		print(Config.Test.Value)
		Config.Test.Value = false
		script.Parent.Toggle.Text = "Off"
	end
end)



local function getValue()
	updateValue()
	if Config.Test.Value == true then
		script.Parent.Toggle.Text = "On"
	else
		script.Parent.Toggle.Text = "Off"
	end
end

getValue()

Server Side:

local Settings = script.Parent:WaitForChild("Settings")
local Config = script.Parent.Parent:WaitForChild("Config")
local DatastoreService = game:GetService("DataStoreService")
local TestValue = DatastoreService:GetDataStore("TestValue")



Settings.OnServerInvoke = function(player, valueupdater, data)
	if valueupdater == "GetData" then
		return TestValue:GetAsync("key_".. player.UserId)
	elseif valueupdater == "UpdateData" then
		TestValue:SetAsync("key_".. player.UserId, {data.Value})
	end
end

GUI Folder:
image

Anything might help.

1 Like

SetAsync has a request cooldown of about 6 seconds for the same key. If you’ve clicked the button numerous times within that threshold, it’ll throw a throttling warning.

You could handle that by making sure enough time has elapsed before firing SetAsync again, but it’s not necessarily a game-breaking error, it just can’t process the request at the time when SetAsync was executed.

1 Like

so by making a cooldown debounce?

Yeah basically. Implement this in your server code.

local activeKeys = {}

local function canSetData(key)
if activeKeys[key] and (os.time() - activeKeys[key] < 6) then return false end

activeKeys[key] = os.time()
return true
end

--//Verify canSetData returns true before trying new set request
1 Like