I am having trouble updating a users shop data, the problem is that the following image is the before and after of whats returned in the UpdateAsync function. But once I load into the game
Purchasing a ability
Loading the shop
Code for updating the items:
module.updateItems = function(plr,name,id)
if not name then
warn("No name specified")
return
end
if not id then
warn("No ID specified")
end
warn(id)
local success,err
local attempt = 1
repeat
success,err = pcall(function()
shop_data:UpdateAsync(plr.UserId,function(oldVal)
warn(oldVal)
if not oldVal then
oldVal = {}
oldVal[name] = table.clone(DATA[name])
oldVal[name].items = {}
end
if not oldVal[name] then
oldVal[name] = table.clone(DATA[name])
oldVal[name].items = {}
end
oldVal[name].items[id] = table.clone(DATA[name].items[id])
cache[plr.UserId] = oldVal
warn(oldVal)
warn(oldVal[name].items[id])
return oldVal
end)
end)
attempt += 1
if not success then
warn(err)
task.wait(3)
end
until success or attempt == 5
if success then
print("Succesfully added",id,"to",name,"for",plr.UserId)
return true
else
warn("Could not add the item.")
return nil
end
end