When I print purchaseHistory I get a table followed by it’s memory position, which is expected, but inside the update call, newValue/oldValue are nil. Any suggestions or ideas?
There’s not enough code here to determine what the source of your problem is. The only thing I do know is that newValue is nil because oldValue is. What is the table of PurchaseHistory and what does the function Update perform?
If DataStore2 hasn’t cached the value of your purchasehistory datastore, the oldValue argument passed in the Update callback function will be nil. There’s an existing issue on Github for it and it’s mentioned in the API documentation.
Ensuring the value is cached before using the Update method solves the problem. Simply calling DataStore:Get with the default value argument should be sufficient.
local ds2 = require(game:GetService("ReplicatedStorage").ds2)
game:GetService("Players").PlayerAdded:Connect(function(Player)
local ph = ds2("ph", Player)
local ph_value = ph:Get(0) --< remove this line and oldVal will be nil, even if data has been previously saved.
ph:Update(function(oldVal)
print(oldVal)
return oldVal
end)
end)