Hello everyone,
I’ve developed an inventory system in which the inventory is recorded in a datastore as a json-encoded string, and when the player enters the game this string is decoded and then made into a folder which other scripts may easily reference and alter, and upon the player exiting this process is done in reverse and the folder is made into a json-encoded string which is updated to the player’s datastore.
This has been working for me thus far, but I’ve began to notice inconsistent behavior in which the player’s data can be successfully retrieved, but isn’t properly saved whenever I use the “Play” button in studio. However this issue doesn’t occur when I test it with the local server button in a server with one or more individuals.
I tried to debug this by having my Save function GetAsync immediately after updating it, so I could confirm if saving was the issue, however for some reason the print statements after the UpdateAsync sequence don’t run?
Code for save function:
function ItemsAndAbilitiesStoreFunctions.Save(player)
local userId = player.UserId
local key = "Player_" .. tostring(userId)
local PossessionsInformation = player:FindFirstChild("PossessionsInformation")
local ItemsPossessionDictionary = ItemsAndAbilitiesStoreFunctions.SetupDictionaryFromPossessionsFolder(player:FindFirstChild("PossessionsInformation"))
print("prior to encoding")
print(ItemsPossessionDictionary)
local EncodedDictionary = HttpService:JSONEncode(ItemsPossessionDictionary)
print("after encoding")
print(EncodedDictionary) -- this statement and ones above print
local success, failure
repeat
success, failure = pcall(function()
ItemsAndAbilitiesStore:UpdateAsync(key, function(oldValue)
return EncodedDictionary
end)
end)
until success
print("observe") -- this statement doesn't print
print(ItemsAndAbilitiesStore:GetAsync(key)) -- this statement doesn't print
end
Thanks in advance.