Data Store Queue

Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()

		PlayerDS:SetAsync(player.UserId, player.leaderstats.Exp.Value) -- These
		PlayerDS:SetAsync(player.UserId, player.leaderstats.Level.Value) -- Three
		--
		PlayerDS:SetAsync(player.UserId, player.Values.MaxExp.Value) -- Lines
		
	end)	
	--
	--
	if success then
		print("Player Data Fully Saved!")
	else
		print("There Was An Error To Save Player Data.")
		warn(errormessage)
	end
end)	

In the pcall function I want to know if there is a way to save multiple things at once without overloading the queue. Because when I look in the output it says that the queue was overloaded and only one value was saved instead of the other two.

Any help is appreciated!

Hello! I am using a different Datastore where i can save [i tested it as well] more than 50 values without overloading anything.

Here’s my Code and my Setup:

[CODE]
local PlayerStatsDS = game:GetService(“DataStoreService”):GetDataStore(“AvatarDataStore_1”)

game.Players.PlayerAdded:Connect(function(NP)

local Key = "PDS-".. NP.UserId

local GetSave = PlayerStatsDS:GetAsync(Key)

local PSF = Instance.new("Folder", NP)
PSF.Name = "CharacterData" --Your datastore Name

local StatsFolder = script.Stats

for i, S in pairs(StatsFolder:GetChildren()) do
	local NS = Instance.new(S.ClassName, PSF)
	NS.Name = S.Name
	NS.Value = S.Value
end

if GetSave then
	for n, Stat in pairs(PSF:GetChildren()) do
		Stat.Value = GetSave[n]
	end
else
	local STS = {}
	for i, Stat in pairs(StatsFolder:GetChildren()) do
		table.insert(STS, Stat.Value)
	end
	PlayerStatsDS:SetAsync(Key, STS)
end

end)

game.Players.PlayerRemoving:connect(function(OP)

local Key = "PDS-".. OP.UserId

local StatsFolder = OP.CharacterData --Your datastore name

local STS = {}
for _, Stat in pairs(StatsFolder:GetChildren()) do
	table.insert(STS, Stat.Value)
end
PlayerStatsDS:SetAsync(Key, STS)

end)

Setup:
image

Hope it helps! :slight_smile:

1 Like

Instead of this use:

PlayerDS:SetAsync(player.UserId, {
	["Exp"] = player.leaderstats.Exp.Value,  
	["Lvl"] = player.leaderstats.Level.Value, 
	["MaxExp"] = player.Values.MaxExp.Value,
})

Then when you load the data use:

loadedData.Exp -- Exp
loadedData.Lvl -- Lvl
loadedData.MaxExp -- MaxExp

Though one problem which can occure, the player might not have any data or have some data not saved before, so we’d need to make sure of that. So when setting data use:

Exp.Value = (loadedData and loadedData["Exp"]) or 0
Lvl.Value = (loadedData and loadedData["Lvl"]) or 1
MaxExp.Value = (loadedData and loadedData["MaxExp"]) or 100

The last digit is the default value, so when you first join etc. You have to make sure to edit that as well as the index of the table.

1 Like

So, your problem lies here.
What youre doing is saving over the last saved data 3 times, that data store will only contain one value, not 3.

You’ll have to save a table of data instead.

local Data = {
	["LEVEL"] = player.leaderstats.Level.Value;
	["EXP"] = player.leaderstats.Exp.Value;
	["MAXEXP"] = player.Values.MaxExp.Value;
}
PlayerDS:SetAsync(player.UserId, Data)

--[[
To load values, this is what it would be:

local DefaultValues = {
	["LEVEL"] = 1;
	["EXP"] = 0;
	["MAXEXP"] = p500;
}

local Data = PlayerDS:GetAsync(player.UserId)

-- Create Values here

player.leaderstats.Level.Value = Data.LEVEL or DefaultValues.LEVEL
player.leaderstats.Exp.Value = Data.EXP or DefaultValues.EXP
player.Values.MaxExp.Value = Data.MAXEXP or DefaultValues.MAXEXP
]]
1 Like

Lol, I guess I have given you two solutions, but this works great! Thank you!

1 Like

Anytime you need me I’d be glad to help you out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.