So, I decided to use UpdateAsync to save and update data. But I am having a problem doing both, my script doesn’t save or update data.
I switched to UpdateAsync only because when I would use SetAsync would override other tables I had saved.
I tried searching how to properly save tables using UpdateAsync but I can’t seem to find any right ways, all the ones I saw don’t explain they just give the scripts out.
UpdateAsync Script
local success, errormessage = pcall(function()
myDataStore:UpdateAsync(key,function(oldData)
local newData = oldData or SavedItemIDs
for i, item in pairs(ItemsFolder:GetChildren()) do --Items
newData.x[item.Name] = item.Value
end
return newData
end)
end)
What x is being set to
if player:FindFirstChild("SlotUS") then --If the player has "SlotUS" in it, then the value of x will equal Outfit1
x = "Outfit1"
elseif player:FindFirstChild("SlotNVA") then --If the player has "SlotNVA" in it, then the value of x will equal Outfit2
x = "Outfit2"
elseif player:FindFirstChild("SlotALLIED") then --If the player has "SlotALLIED" in it, then the value of x will equal Outfit3
x = "Outfit3"
end
What SavedItemsIDs is
--NoDataUS, NoDataNVA, NoDataAL are preset outfits for players that have no data saved
local SavedItemIDs = {
["Outfit1"] = {},
["Outfit2"] = {},
["Outfit3"] = {},
["NoDataUS"] = {["M1C"] = "hat",["Pants"] = "http://www.roblox.com/asset/?id=5053577948",["Shirt"] = "http://www.roblox.com/asset/?id=5054465259",["Trecky1"] = "hair",["Web"] = "web",["face"] = "http://www.roblox.com/asset/?id=1942392454",["skin"] = "Pastel brown"},
["NoDataNVA"] = {["M1"] = "hat",["Pants"] = "http://www.roblox.com/asset/?id=5053577948",["Shirt"] = "http://www.roblox.com/asset/?id=5054376077",["Trecky1"] = "hair",["Web"] = "web",["face"] = "http://www.roblox.com/asset/?id=343187883",["skin"] = "Nougat"},
["NoDataAL"] = {["M1C"] = "hat",["Pants"] = "http://www.roblox.com/asset/?id=4831959204",["Shirt"] = "http://www.roblox.com/asset/?id=4831982288",["Trecky1"] = "hair",["Web1"] = "web",["face"] = "http://www.roblox.com/asset/?id=343187883",["skin"] = "Pastel brown"}
}