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

So whenever I exit out of Play test in the studio I get that in the output. HEres the script

local DataSaveService = game:GetService("DataStoreService")
local stat = DataSaveService:GetDataStore("Stats")

game.Players.PlayerAdded:Connect(function(plr)
	local attributes = Instance.new("Folder", plr)
	attributes.Name = "Attributes"
	local breathing = Instance.new("IntValue", attributes)
	breathing.Name = "Breathing"
	local health = Instance.new("IntValue", attributes)
	health.Name = "Health"
	local speed = Instance.new("IntValue", attributes)
	speed.Name = "Speed"
	
	local breathings
	local healths
	local speeds
	-- data store time :)
	local success, errormsg = pcall(function()
		breathings = stat:GetAsync(plr.UserId.."-Breathing")
		healths = stat:GetAsync(plr.UserId.."-Health")
		speeds = stat:GetAsync(plr.UserId.."-Speed")
	end)
	if success then
		breathing.Value = breathings
		health.Value = healths
		speed.Value = speeds
		print("The player data has been saved") -- this will print if the scrip successfully loaded the players data
	else
		print("player data load error") -- this will print if the player's data failed at loading
		warn(errormsg) -- this will tell the problem of the load error
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormsg = pcall(function()
		stat:SetAsync(plr.UserId.."-Breathing", plr.Attributes.Breathing.Value)
		stat:SetAsync(plr.UserId.."-Health", plr.Attributes.Health.Value)
		stat:SetAsync(plr.UserId.."-Speed", plr.Attributes.Speed.Value)
	end)
	if success then
		print("Player data got saved")
	else
		print("Failed at saving data")
		warn(errormsg)
	end
end)

It means the Datastore is getting overloaded by the number of requests it has been getting. Are you saving the value as soon as it changes or increases?

It’s usually frowned upon to save/load from multiple keys in a datastore, a better method would be saving just one table to one key:

-- on PlayerAdded

-- data store time :)
local success, data = pcall(function()
    return stat:GetAsync(plr.UserId)
end)

if success then
    breathing.Value = data.breathing
    -- and the other stuff
else
    print("player data load error") -- this will print if the player's data failed at loading
    warn(data) -- this will tell the problem of the load error
end

-- ...
-- on PlayerRemoving

local newData = {
    breathing = plr.Attributes.Breathing.Value,
    health = plr.Attributes.Health.Value
    speed = plr.Attributes.Speed.Value
}
local success, errormsg = pcall(function()
	stat:SetAsync(plr.UserId, newData)
end)
if success then
	print("Player data got saved")
else
	print("Failed at saving data")
	warn(errormsg)
end

-- ...
1 Like

In the script it says Unknown Global for errormsg
But otherwise it worked, thanks. Im not good at datastores.