from my personal experience with roblox datastores, I believe using two data stores (one hosting the outfits, and another hosting the owners of the specific outfits) would work fine.
we save outfits inside an OutfitIDStore with a unique ID (generate a unique ID and save a table with all the IDs)
and then append that same ID to a user's outfits list (get the user's table and append the outfit ID to it)
this code has NOT been tested
local DataStoreService = game:GetService('DataStoreService')
local OutfitIDStore = DataStoreService:GetDataStore('OUTFIT_STORE')
local UserIDStore = DataStoreService:GetDataStore('USER_STORE')
local Chars = ('abcdefghijklmnopqrstuvwxyz0123456789').split('')
local GenericLength = 6
local function GetOutfitIDStore(key)
if key == nil then
error(('missing argument key (got %s, expected not nil)').format(tostring(key)))
end
return pcall(function()
OutfitIDStore:GetAsync(key)
end)
end
local function SetOutfitIDStore(key, data)
if key == nil then
error(('missing argument key (got %s').format(tostring(key)))
end
if data == nil then
error(('missing argument data (got %s)').format(tostring(key)))
end
return pcall(function()
OutfitIDStore:SetAsync(key, data)
end)
end
local function GetUserIDStore(key)
if key == nil then
error(('missing argument key (got %s, expected not nil)').format(tostring(key)))
end
return pcall(function()
UserIDStore:GetAsync(key)
end)
end
local function SetUserIDStore(key, data)
if key == nil then
error(('missing argument key (got %s').format(tostring(key)))
end
if data == nil then
error(('missing argument data (got %s)').format(tostring(key)))
end
return pcall(function()
UserIDStore:SetAsync(key, data)
end)
end
local function GenerateUniqueID(length: int)
if type(length) ~= 'number' then
length = GenericLength
end
local ID = ''
for i = 1, length do
ID = ID + Chars[math.random(1, #Chars)]
end
local ok, data = GetOutfitIDStore(ID)
if not ok and type(data) ~= 'table' then
return ID
else
return GenerateUniqueID(length)
end
end
local function SaveOutfit(Accessories: table, UserID: int)
assert(Accessories, 'no accessories provided.')
assert(UserID, 'no userid provided.')
local ID = GenerateUniqueID()
local UploadSuccess, Message = SetOutfitIDStore(ID, Accessories)
if not UploadSuccess and Message ~= nil then
end
local GetSuccess, Data = GetUserIDStore(UserID)
if not GetSuccess and Data == nil then
end
local UpdatedTable = Data
table.insert(UpdatedTable, ID)
local SetSuccess, Message = SetUserIDStore(UserID, UpdatedTable)
if not SetSuccess and Message ~= nil then
end
end
local function RemoveOutfit(ID: str, UserID: int)
local GetSuccess, Data = GetUserIDStore(UserID)
if not GetSuccess and Data == nil then
end
if not table.find(Data, ID) then
return false, ('User %i is not the owner of outfit (%s)').format(UserID, ID)
end
local UpdatedTable = Data
table.remove(UpdatedTable, table.find(Data, ID))
local SetSuccess, Message = SetUserIDStore(UserID, UpdatedTable)
if not SetSuccess and Message ~= nil then
end
end
local function GetOutfitFromID(ID)
return GetOutfitIDStore(ID)
end
local function GetUserOufits(UserID)
return GetUserIDStore(UserID)
end
3 comments
That's what I originally thought, but that option wouldn't allow browsing the outfits, would it?
i assume you mean browsing by listing every outfit created. no, that wouldn't be possible unless you used an OrderedDataStore (replacing the Outfit_Store GetDataStore with OrderedDataStore), if you wish I could upload a version of the script with that included.
that'd be great!