I made an in-game cosmetic shop where players can buy Trails, Auras, and Gear, however I had made each cosmetic it’s own datastore and as such I was presented with the this warning:
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests
So as means of curbing this I decided to try to merge all the data stores into one massive store for all the cosmetics when the player leaves the game. However I am now presented with a new problem, that being how I would reload all the players assets from their datastore. This is as certain items use the same names as others (ie. an orange trail is being saved as well as an orange aura).
Here is the script to save the player's data upon leaving (I had a previous script already saving the players Cash, Wins, and 'ChestTime' so I just decided to combine the save function with that). I have also obfuscated some parts of the code so it would be easier to read.
local PlayersService=game:GetService('Players')
local DataStoreService=game:GetService('DataStoreService')
local ds = DataStoreService:GetDataStore("DATA")
local DataStore=DataStoreService:GetDataStore(":ChestData")
local CurrencyStore=DataStoreService:GetDataStore(":Currency")
local WinsStore = DataStoreService:GetDataStore(":Wins")
PlayersService.PlayerRemoving:Connect(function(Player)
if Player:FindFirstChild("ChestData") and Player.ChestData.Value==true then
if not ChestSettings.CreateNewCurrency then return end
local Success,Errormsg=pcall(function()
CurrencyStore:SetAsync(Player.UserId, Player.leaderstats[ChestSettings.CurrencyName].Value)
WinsStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
-- AURAS
local ownedTrails = {}
for i, trail in pairs(Player.OwnedTrails:GetChildren()) do -- CHANGE THIS
table.insert(ownedTrails, trail.Name)
end
-- GEARS
local ownedGears = {}
for i, trail in pairs(Player.OwnedGears:GetChildren()) do -- CHANGE THIS
table.insert(ownedGears, trail.Name)
end
-- TRAILS
local ownedAuras = {}
for i, trail in pairs(Player.OwnedAuras:GetChildren()) do -- CHANGE THIS
table.insert(ownedAuras, trail.Name)
end
-- COMBINE TABLES
local ownedEverything = {}
for i, TableChild in pairs (ownedTrails) do
table.insert(ownedEverything, ownedTrails)
end
for i, TableChild in pairs (ownedGears) do
table.insert(ownedEverything, ownedGears)
end
for i, TableChild in pairs (ownedAuras) do
table.insert(ownedEverything, ownedAuras)
end
local success, err = pcall(function()
ds:SetAsync("allitmes-" .. Player.UserId, ownedEverything) -- CHANGE THIS
end)
end)
if not Success then warn(Errormsg) else print("Saved Currency") end
end
end)
.
.
.
And here is my (albeit unfinished as I didn't know how to continue on) script which would load the players auras (again some bits obfuscated)
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("DATA")
local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Customization")
-- CHANGE THIS
local auras = SS:WaitForChild("Cosmetics"):WaitForChild("Auras")
local Choose = Events:WaitForChild("AuraChooseRE")
local Buy = Events:WaitForChild("AuraBuyRE")
-- player added
game.Players.PlayerAdded:Connect(function(plr)
local aurasOwned = {}
pcall(function()
aurasOwned = ds:GetAsync("allitmes-" .. plr.UserId) or {} -- CHANGE THIS
end)
local ownedFolder = Instance.new("Folder", plr)
ownedFolder.Name = "OwnedAuras" -- CHANGE THIS
for i, owned in pairs(aurasOwned) do
if auras:FindFirstChild(owned) then
auras[owned]:Clone().Parent = ownedFolder
end
end
end)
The script managing the players auras, gears, and trails have all more or less the same implications.
What practice should I go about doing so as to load the player’s data?
I have thought about so far:
- Changing the names of items (OrangeTrail, OrangeAura, BlueAura, BloxyColaGear), however I would not know how to occlude and index “Gear” / “Trail” / “Aura”
- Whether the object’s class would be saved or not and if I could just modify my scripts to work around that