I wanna convert my data store system to use UpdateAsync, however, I’ve never used it before, as SaveAsync has never caused me problems in the past, but everyone says I should change it. I’ve tried to use DataStore2, but that was way too complex for what I needed (all the tutorials only taught how to save individual values)
Problem with my datastore is I have multiple mixed values, inluding tables within tables, etc.
Here’s how my data is structured
return {
-- Main Data
Coins = 100000,
Level = 1,
Exp = 0,
FavouriteColor = {107, 184, 217},
Codes = {},
StarterPackUsed = false,
Quests = {},
-- House Data
House = 'Default',
Houses = {
['Default'] = {
Exterior = {},
House = {},
Purchases = {}
},
},
Furniture = {},
-- Character Data
Character = {
Name = '',
Age = 'Adult',
HatAccessories = {},
HairAccessories = {},
FaceAccesssories = {},
NeckAccessories = {},
ShoulderAccessories = {},
BackAccesssories = {},
WaistAccesssories = {},
Face = '',
Shirt = '',
Pants = '',
Color = 'Light orange',
},
}
And when I wanna update say the players cash I’d just go into their data and do like
local User = PlayerData[Player.UserId]
if not User then return end
User.Cash = User.Cash + 10
And it’d basically be the same for all data updates.
local User = PlayerData[Player.UserId]
if not User then return end
User.House = 'Other House'
-- etc...
Problem lies with the ‘Houses’ table. To get that I got all the items inside the players house, stored it all in tables, named, etc. and then placed those respective tables under each section (Exterior, House, Purchases) and it worked great. And to save all I do is just use to SetAsync when the player leaves
So I fear using UpdateAsync would just cause more nightmares than solutions.
Please for the love of logic, DO NOT just link me to UpdateAsync pages/forum posts. I’ve read them all, and then re-read them. They haven’t helped thus far.
For those who are curious how I save the Houses data
local Items = {Exterior = {}, House = {}, Purchases = {}}
for _, v in pairs(PlayersPlot.Plot:GetDescendants()) do
if v:IsA('BrickColorValue') then
Items.Exterior[v.Parent.Name] = (v.Value).Name
end
end
for _, item in pairs(PlayersHouse.House.Purchases:GetChildren()) do
local PurchaseData = {}
local PrimaryPart = item.PrimaryPart
local Position = PlayersHouse.PrimaryPart.CFrame:inverse() * PrimaryPart.Position
local Direction = PrimaryPart.CFrame.lookVector
PurchaseData.ItemName = item.Name
PurchaseData.Position = {
Position.X,
Position.Y,
Position.Z,
Direction.X,
Direction.Y,
Direction.Z
}
local Primary = item:FindFirstChild('Primary')
PurchaseData.Primary = Primary.BrickColor.Name
local Secondary = item:FindFirstChild('Secondary')
if Secondary then
PurchaseData.Secondary = Secondary.BrickColor.Name
local Tertiary = item:FindFirstChild('Tertiary')
if Tertiary then
PurchaseData.Tertiary = Tertiary.BrickColor.Name
end
end
Items.Purchases[#Items.Purchases + 1] = PurchaseData
end
for _, item in pairs(PlayersHouse.House.House:GetDescendants()) do
if item:IsA('BasePart') or item:IsA('UnionOperation') then
local HouseData = {}
HouseData.ItemName = item.Name
HouseData.Texture = item.Texture.Texture
Items.House[#Items.House + 1] = HouseData
end
end
local User = PlayerData[player.UserId]
if not User then return end
User.Houses[User.House] = Items