I know this seems basic to most people, but I've hit a huge roadblock when it comes to saving data. I have quite a bit of stat values that I want to save and load every time they join the game and I tried a number of different ways to save everything without overloading my requests at saving data and none seem to have worked.

This is my latest version and I get this in the output:

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

local DataStoreService = game:GetService("DataStoreService")
local cashSave = DataStoreService:GetDataStore("CashStorage")
local daySave = DataStoreService:GetDataStore("DayStorage")
local pSave = DataStoreService:GetDataStore("PSave")
local oSave = DataStoreService:GetDataStore("OSave")
local mSave = DataStoreService:GetDataStore("MSave")
local sSave = DataStoreService:GetDataStore("SSave")
local bpSave = DataStoreService:GetDataStore("BPSave")
local hSave = DataStoreService:GetDataStore("HSave")
local cSave = DataStoreService:GetDataStore("CSave")
local bSave = DataStoreService:GetDataStore("BSave")

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

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local day = Instance.new("IntValue")
	day.Name = "Day"
	day.Value = "0"
	day.Parent = leaderstats
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = "0"
	cash.Parent = leaderstats
	
--Ingredient stats
	
	local ingredients = Instance.new("Folder")
	ingredients.Name = "Ingredients"
	ingredients.Parent = player
	
	local pineapple = Instance.new("IntValue")
	pineapple.Name = "Pineapple"
	pineapple.Parent = ingredients
	pineapple.Value = "0"
	
	local olive = Instance.new("IntValue")
	olive.Name = "Olive"
	olive.Parent = ingredients
	olive.Value = "0"
	
	local mushroom = Instance.new("IntValue")
	mushroom.Name = "Mushroom"
	mushroom.Parent = ingredients
	mushroom.Value = "0"
	
	local spinach = Instance.new("IntValue")
	spinach.Name = "Spinach"
	spinach.Parent = ingredients
	spinach.Value = "0"
	
	local bananapepper = Instance.new("IntValue")
	bananapepper.Name = "Banana Pepper"
	bananapepper.Parent = ingredients
	bananapepper.Value = "0"
	
	local ham = Instance.new("IntValue")
	ham.Name = "Ham"
	ham.Parent = ingredients
	ham.Value = "0"
	
	local chicken = Instance.new("IntValue")
	chicken.Name = "Chicken"
	chicken.Parent = ingredients
	chicken.Value = "0"
	
	local bacon = Instance.new("IntValue")
	bacon.Name = "Bacon"
	bacon.Parent = ingredients
	bacon.Value = "0"
	
	
--saves data on change
	--Cash 
	cash.Value = cashSave:GetAsync(player.UserId) or 0
 	cashSave:SetAsync(player.UserId, cash.Value)
 	cash.Changed:connect(function()
 	cashSave:SetAsync(player.UserId, cash.Value)
	end)
	--Day
	day.Value = daySave:GetAsync(player.UserId) or 0
 	daySave:SetAsync(player.UserId, day.Value)
 	day.Changed:connect(function()
 	daySave:SetAsync(player.UserId, day.Value)
	end)
--Ingredients
	--Pineapple
	pineapple.Value = pSave:GetAsync(player.UserId) or 0
 	pSave:SetAsync(player.UserId, pineapple.Value)
 	pineapple.Changed:connect(function()
 	pSave:SetAsync(player.UserId, pineapple.Value)
	end)
	--Olive
	olive.Value = oSave:GetAsync(player.UserId) or 0
 	oSave:SetAsync(player.UserId, olive.Value)
 	olive.Changed:connect(function()
 	oSave:SetAsync(player.UserId, olive.Value)
	end)
	--mushroom
	mushroom.Value = mSave:GetAsync(player.UserId) or 0
 	mSave:SetAsync(player.UserId, mushroom.Value)
 	mushroom.Changed:connect(function()
 	mSave:SetAsync(player.UserId, mushroom.Value)
	end)
	--Spinach
	spinach.Value = sSave:GetAsync(player.UserId) or 0
 	sSave:SetAsync(player.UserId, spinach.Value)
 	spinach.Changed:connect(function()
 	sSave:SetAsync(player.UserId, spinach.Value)
	end)
	--Banana Pepper
	bananapepper.Value = bpSave:GetAsync(player.UserId) or 0
 	bpSave:SetAsync(player.UserId, bananapepper.Value)
 	bananapepper.Changed:connect(function()
 	bpSave:SetAsync(player.UserId, bananapepper.Value)
	end)
	--Ham
	ham.Value = hSave:GetAsync(player.UserId) or 0
 	hSave:SetAsync(player.UserId, ham.Value)
 	ham.Changed:connect(function()
 	hSave:SetAsync(player.UserId, ham.Value)
	end)
	--Chicken
	chicken.Value = cSave:GetAsync(player.UserId) or 0
 	cSave:SetAsync(player.UserId, chicken.Value)
 	chicken.Changed:connect(function()
 	cSave:SetAsync(player.UserId, chicken.Value)
	end)
	--Bacon
	bacon.Value = bSave:GetAsync(player.UserId) or 0
 	bSave:SetAsync(player.UserId, bacon.Value)
 	bacon.Changed:connect(function()
 	bSave:SetAsync(player.UserId, bacon.Value)
	end)
	
--cash load when join
	local data
	local success, errormessage = pcall(function()
		data = cashSave:GetAsync(player.UserId.."-cash")
	end)
		
	if success then
		cash.Value = data
	else
		print("Error getting Cash Data")
		warn(errormessage)
	end
--day load when join
	local data2 
	local success, errormessage = pcall(function()
		data2 = daySave:GetAsync(player.UserId.."-day")
	end)
	
	if success then
		day.Value = data2
	else
		print("Error getting Day Data")
		warn(errormessage)
	end
	print("Player Join Successfully")
end)

I haven't written it where it loads every topping yet because I'm overloading my requests without them.

Does anyone know any alternative ways where I can possibly save all of these with a simpler and more efficent function?

3 comments

0

too many data requests

0

You can either use one data store for all of them. Or just do not save all of them at the same time. This will cause all saves to overload

0

@messi55313 So if I save them all on the same data store will I need a table?