Datastore2 queue

Hiya, my datastore2 script has a LOT of queue warnings, there’s a lot of things it loads.

How can I stop this?

The script (be prepared! ITS LONG)

local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))

--Data
local DataList = {
	["Level"] = 1,
	["Exp"] = 0,
	["Coins"] = 750,
	["Skin"] = 0,
	["Face"] = 0,
	["Hair"] = 0,
	["Outfit"] = 0,
	["Shoes"] = 0,
	["HeadAcc"] = 0,
	["FaceAcc"] = 0,
	["BodyAcc"] = 0,
	["Wallpaper"] = 0,
	["Icon"] = 0,
	["Charm"] = 0,
	["House"] = 0,
	["HouseMusic"] = 0,
	["skin1"] = 0,
	["hair1"] = 0,
	["face1"] = 0,
	["outfit1"] = 0,
	["shoe1"] = 0,
	["headacc1"] = 0,
	["faceacc1"] = 0,
	["bodyacc1"] = 0,
	["skin2"] = 0,
	["hair2"] = 0,
	["face2"] = 0,
	["outfit2"] = 0,
	["shoe2"] = 0,
	["headacc2"] = 0,
	["faceacc2"] = 0,
	["bodyacc2"] = 0,
	["skin3"] = 0,
	["hair3"] = 0,
	["face3"] = 0,
	["outfit3"] = 0,
	["shoe3"] = 0,
	["headacc3"] = 0,
	["faceacc3"] = 0,
	["bodyacc3"] = 0,
	["Slime"] = 0,
	["Mushroom"] = 0,
	["Coral"] = 0,
	["Pearl"] = 0,
	["Diamond"] = 0,
	["Basic"] = 0,
	["Common"] = 0,
	["Legendary"] = 0,
	["Rare"] = 0,
	["Ultra"] = 0,
}

--Charms
local CharmList = {
	["1"] = 0, --Beta 7359498417
	["2"] = 0, --Boba 7359498029
	["3"] = 0, --Coins 7359496712
	["4"] = 0, --Donut 7359497706
	["5"] = 0, --Flower 7359497433
	["6"] = 0, --LifeRing 7359496980
	["7"] = 0, --Pinata 7359496468
	["8"] = 0, --Pizza 7359496287
	["9"] = 0, --Shell 7359495969
	["10"] = 0, --Starfish 7359495726
	["11"] = 0, --Turtle 7359494849
}

--Wallpapers
local WallpaperList = {
	["1"] = 0, --Beta 7388167080
	["2"] = 0, --Blossom 7420464674
	["3"] = 0, --Camo 7420464973
	["4"] = 0, --Disco 7358764467
	["5"] = 0, --Garden 7388111419
	["6"] = 0, --Homework 7388111207
	["7"] = 0, --Ice 7420464138
	["8"] = 0, --Maple 7420463909
	["9"] = 0, --Metal 7420464420
	["10"] = 0, --Space 7388110852
	["11"] = 0, --Sunset 7358764078
	["12"] = 0, --Underwater 7358763735
}

--Hairs
local HairList = {
	["1"] = 0, --Adventurer 6432078177
	["2"] = 0, --BeachWaves 6412355050
	["3"] = 0, --BlondePopstar 6553141167
	["4"] = 0,  --BoyBandBrown 6420676260
	["5"] = 0, --BoyBandGrey 6420662971
	["6"] = 0, --BraidedBun 6592417649
	["7"] = 0, --BubblegumPopstar 6553140401
	["8"] = 0, --CocoBuns 6860836089
	["9"] = 0, --ColorfulDreads 7381702574
	["10"] = 0, --DiamondPrincess 6426716500
	["11"] = 0, --ExtremeHairPink 7381702434
	["12"] = 0, --ExtremeHairPurple 7381702262
	["13"] = 0, --FashionistaBlack 6540332970
	["14"] = 0, --KawaiiBlue 6430619559
	["15"] = 0, --KawaiiCaramel 6430617851
	["16"] = 0, --MermaidBlue 6430517013
	["17"] = 0, --MermaidPink 6426714816
	["18"] = 0, --MidnightPunkBlue 6927521466
	["19"] = 0, --MidnightPunkRed 6927521226
	["20"] = 0, --PurpleRocket 6927521364
	["21"] = 0, --PurpleWaves 6412358116
	["22"] = 0, --RockstarHair 6463257613
	["23"] = 0, --SpikeyBlonde 6432076782
	["24"] = 0, --SpikeyRed 6432074798
	["25"] = 0, --SunsetPonytail 6412401108
	["26"] = 0, --WizardCut 6430535125
}

--Outfits
local OutfitList = {
	["1"] = 0, --BetaOutfit 7388502294
	["2"] = 0, --CactusOveralls 6402223788
	["3"] = 0, --ChefOutfit 7151361044
	["4"] = 0, --CloverShirtOutfit 6553103125
	["5"] = 0, --CozyAttireBeige 7151360884
	["6"] = 0, --CozyAttireBlue 7151361317
	["7"] = 0, --CozyAttirePink 7151360608
	["8"] = 0, --DiamondGown 6426723654
	["9"] = 0, --DuckShirtOutfit 6553120712
	["10"] = 0, --EarthSpirit 6411748800
	["11"] = 0, --GeekyOutfit 6706189802
	["12"] = 0, --HeartShirtOutfit 6553112142
	["13"] = 0, --HipsterOutfit 6553095589
	["14"] = 0, --JungleAttire 6402789843
	["15"] = 0, --KawaiiEmo 6553092472
	["16"] = 0, --MaidDress 7151360750
	["17"] = 0, --MidnightDress 7388351743
	["18"] = 0, --PoliceOutfit 7151360488
	["19"] = 0, --RockstarOutfit 6463132977
	["20"] = 0, --SchoolSkirt 6326855563
	["21"] = 0, --ScientistOutfit 7388341196
	["22"] = 0, --SpyAttire 7388341025
	["23"] = 0, --StrawberryDress 7151360255
	["24"] = 0, --StudyOutfit 6411738160
	["25"] = 0, --SummerDress 6706176286
	["26"] = 0, --WizardRobes 6426724811
}

--Shoes
local ShoeList = {
	["1"] = 0, --AquaSlipons 6706292509
	["2"] = 0, --BearSlippers 7151905823
	["3"] = 0, --BlueSneakers 6403002091
	["4"] = 0, --GetaSandals 6706300302
	["5"] = 0, --GreenFlipFlops 6402989061
	["6"] = 0, --GreenSneakers 6403018443
	["7"] = 0, --IslandSandals 7435971881
	["8"] = 0, --LegArmour 6426809807
	["9"] = 0, --LegVines 6411773167
	["10"] = 0, --MidnightHeels 7388255702
	["11"] = 0, --OrangeSlipons 6706301968
	["12"] = 0, --PolarBearSlippers 7151905426
	["13"] = 0, --RainBoots 7151905264
	["14"] = 0, --RockerBoots 6463119404
	["15"] = 0, --SchoolShoes 6378367924
	["16"] = 0, --SchoolSneakers 6411771584
	["17"] = 0, --SpyBoots 7152021285
	["18"] = 0, --WizardLoafers 6430656566
}

--HeadAccs
local HeadAccList = {
	["1"] = 0, --Bandana 7353294929
	["2"] = 0, --BeanieBeige 7152155526
	["3"] = 0, --BeanieBlue 7152155365
	["4"] = 0, --BeaniePink 7152155102
	["5"] = 0, --BeeHairClip 7152155685
	["6"] = 0, --BetaHat 7353294759
	["7"] = 0, --BlueBow 6378390825
	["8"] = 0, --CarnivalHat 6806921413
	["9"] = 0, --ChefHat 7152155227
	["10"] = 0, --DesertHairClip 6432020879
	["11"] = 0, --DiamondHeadPeice 6426834008
	["12"] = 0, --GreenBow 6326668904
	["13"] = 0, --HairLeaf 6432022483
	["14"] = 0, --PinkBow 6326670405
	["15"] = 0, --PoliceHat 7152154995
	["16"] = 0, --RainbowHeadphones 6806920707
	["17"] = 0, --StrawHat 7152154770
	["18"] = 0, --WizardHat 6426834750
}

--FaceAccs
local FaceAccList = {
	["1"] = 0, --BlackMoustache 6420926054
	["2"] = 0, --BlackShades 6706738033
	["3"] = 0, --BlueSleepingMask 7353294455
	["4"] = 0, --BrownMoustache 6420924969
	["5"] = 0, --BullHorns 7353294611
	["6"] = 0, --CarnivalGlasses 6806918495
	["7"] = 0, --FlowerAndEarring 6378413927
	["8"] = 0, --GeekyGlasses 6706511111
	["9"] = 0, --GoldEarPeice 6426853864
	["10"] = 0, --PinkSleepingMask 7353294229
	["11"] = 0, --RockstarTattoo 6462976030
	["12"] = 0, --SpyGlasses 7152055898
	["13"] = 0, --ScienceGoggles 7152056048
}

--BodyAccs
local BodyAccList = {
	["1"] = 0, --Balloons 6806907579
	["2"] = 0, --ArcadeTickets 6806920574
	["3"] = 0, --BlueBook 6706654043
	["4"] = 0, --BlueCloud 6806921289
	["5"] = 0, --BlueTie 6378423445
	["6"] = 0, --BowTie 7156009950
	["7"] = 0, --Camera 6706639298
	["8"] = 0, --CottonCandyBlue 6806920834
	["9"] = 0, --CottonCandyPink 6806920957
	["10"] = 0, --DiamondArrow 6426872376
	["11"] = 0, --ElectricGuitar 6463143694
	["12"] = 0, --Potion 7156009747
	["13"] = 0, --PunkBracelet 6706652926
	["14"] = 0, --PurpleCloud 6806921084
	["15"] = 0, --RedBook 6706655060
	["16"] = 0, --SchoolBag 6706655946
	["17"] = 0, --SpyGloves 7156009613
	["18"] = 0, --StrawberryCrossbody 7146372478
	["19"] = 0, --SummerRobe 6706657021
	["20"] = 0, --SwimmingRings 6706661970
	["21"] = 0, --VacationLei 6378425865
	["22"] = 0, --WizardWand 6427143460
}


DataStore2.Combine("DataList", "CharmList", "WallpaperList", "HairList", "OutfitList", "ShoeList", "HeadAccList", "FaceAccList", "BodyAccList")

game.Players.PlayerAdded:Connect(function(plr)
	
	--Load Data
	local DataValue = Instance.new("Folder")
	DataValue.Parent = plr
	DataValue.Name = "Data"
	
	--Load Charms
	local CharmValue = Instance.new("Folder")
	CharmValue.Parent = plr
	CharmValue.Name = "Charm"
	
	--Load Wallpapers
	local WallpaperValue = Instance.new("Folder")
	WallpaperValue.Parent = plr
	WallpaperValue.Name = "Wallpaper"
	
	--Load Hairs
	local HairValue = Instance.new("Folder")
	HairValue.Parent = plr
	HairValue.Name = "Hair"
	
	--Load Outfits
	local OutfitValue = Instance.new("Folder")
	OutfitValue.Parent = plr
	OutfitValue.Name = "Outfit"
	
	--Load Shoes
	local ShoeValue = Instance.new("Folder")
	ShoeValue.Parent = plr
	ShoeValue.Name = "Shoe"
	
	--Load HeadAccs
	local HeadAccValue = Instance.new("Folder")
	HeadAccValue.Parent = plr
	HeadAccValue.Name = "HeadAcc"
	
	--Load FaceAccs
	local FaceAccValue = Instance.new("Folder")
	FaceAccValue.Parent = plr
	FaceAccValue.Name = "FaceAcc"
	
	--Load BodyAccs
	local BodyAccValue = Instance.new("Folder")
	BodyAccValue.Parent = plr
	BodyAccValue.Name = "BodyAcc"

	for i,v in pairs(DataList) do
		local Data = DataStore2("DataList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = DataValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end

	for i,v in pairs(CharmList) do
		local Data = DataStore2("CharmList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = CharmValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
	
	for i,v in pairs(WallpaperList) do
		local Data = DataStore2("WallpaperList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = WallpaperValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end

	for i,v in pairs(HairList) do
		local Data = DataStore2("HairList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = HairValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
	
	for i,v in pairs(OutfitList) do
		local Data = DataStore2("OutfitList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = OutfitValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
	
	for i,v in pairs(ShoeList) do
		local Data = DataStore2("ShoeList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = ShoeValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
	
	for i,v in pairs(HeadAccList) do
		local Data = DataStore2("HeadAccList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = HeadAccValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
	
	for i,v in pairs(FaceAccList) do
		local Data = DataStore2("FaceAccList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = FaceAccValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end	

	for i,v in pairs(BodyAccList) do
		local Data = DataStore2("BodyAccList"..i, plr)
		local NewInst = Instance.new("IntValue")
		NewInst.Parent = BodyAccValue
		NewInst.Name = i
		NewInst.Value = v
		local function updateData(value)
			NewInst.Value = Data:Get(value)
		end
		updateData(v)
		Data:OnUpdate(updateData)
		NewInst.Changed:Connect(function()
			Data:Set(NewInst.Value)
		end)
	end
end)

You are updating the data too many times
use another table to contain all the categories and try

Using just one table didnt fix the issue

Add a loading sequence and use wait(your number)

image
Don’t use .changed for data stores, when the player leaves the game you should save the data then, or else you will get too much warnings.

datastore2 should save on update though I have heard

Here’s the bad example:

local DSS = game:GetService("DataStoreService")
local CDS = DSS:GetDataStore("CoinsDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local playerUserId = player.UserId
	
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local coins = Instance.new("IntValue",leaderstats)
	coins.Name = "Coins"
	coins.Changed:Connect(function()
		CDS:SetAsync(playerUserId, coins.Value)
	end)
	
	local coinsData
	local success, errormessage = pcall(function()
		coinsData = CDS:GetAsync(playerUserId)
	end)
	
	if coinsData ~= nil then
		coins.Value = coinsData
	else
		coins.Value = 0
	end
end

Heres the good example:

local DSS = game:GetService("DataStoreService")
local CDS = DSS:GetDataStore("CoinsDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local playerUserId = player.UserId
	
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local coins = Instance.new("IntValue",leaderstats)
	coins.Name = "Coins"
	
	local coinsData
	local success, errormessage = pcall(function()
		coinsData = CDS:GetAsync(playerUserId)
	end)
	
	if coinsData ~= nil then
		coins.Value = coinsData
	else
		coins.Value = 0
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = player.UserId
	
	local success, errormessage = pcall(function()
		CDS:SetAsync(playerUserId, player:WaitForChild("leaderstats"):WaitForChild("Coins").Value)
	end)
end)