It’s really confusing, I’ve created a savedata bindable function which seems to not be saving data properly. I create a listing then leave, it doesn’t save. but sometimes it does?
local function serializeAttributes(folder)
local data = {}
for attr, value in pairs(folder:GetAttributes()) do
data[attr] = value
end
return data
end
local function getListing(Player)
local existingListings = listingsFolder:GetChildren()
local exactListings = {}
for _, Listing in pairs(existingListings) do
if Listing.Name == Player.Name then
table.insert(exactListings, Listing)
end
end
if #exactListings == 0 then
wait("No listings")
else
print("Found ".. #exactListings)
end
return exactListings
end
saveDataFunction.OnInvoke = function(player, listingUID)
print("SaveData invoked for " .. player.Name)
local userId = player.UserId
local playerListings = getListing(player)
local allData = {}
if playerListings and #playerListings > 0 then
for index, listing in ipairs(playerListings) do
if listing and listing:IsA("Folder") then
local listingData = serializeAttributes(listing)
allData[index] = listingData
else
print("No listings found for " .. player.Name)
--allData = {Rating = player.Rating.Value}
end
end
end
local success, err = pcall(function()
print(allData)
ListingDataStore:SetAsync("Listings_" .. tostring(userId), allData)
end)
if success then
print("Successfully saved data for " .. player.Name)
return true
else
wait("Failed to save data for " .. player.Name)
return false
end
end