for i, Val in pairs(CFolder:GetChildren()) do
local a = coroutine.wrap(function()
local success, errorMsg
local Tries = 0
repeat
success, errorMsg = pcall(function()
return Datastore:GetAsync(Player.UserId.."_"..Val.Name)
end)
task.wait(0.5)
Tries += 1
until success or Tries > 10
if success then
Val.Value = Datastore:GetAsync(Player.UserId.."_"..Val.Name) or Val.Value
else
print("Error when loading : "..Player.Name.." ["..Player.UserId.."]")
end
end)
a()
end
This is a block of code for loading an inventory and for the most part, it works.
Sometimes, it loses stuff and when the player leaves, that item is gone forever since :SetAsync() saves whatever value they were leaving with. (1 = owned item, 0 = not owned)
Is there a way to convert that datastore into some sort of table so it can quickly get data instead of iterating :GetAsync()?
Thanks!
Example: Datastore → table{[apple] = 1, [banana] = 0}