How do I use GetOutfits from AvatarEditorService? / How do I get all of the player's owned outfit IDs?

Hello everyone, I’m trying to make a customizable avatar awakening like The Strongest Battlegrounds. I’m trying to get all of the player’s owned/created outfit IDs by using GetOutfits then pasting the outfit id to the player, I know how to paste the ID to the player but I don’t know how to use GetOutfits or get all of the player’s owned/created outfits. So I found GetOutfits but I don’t know how to use this. Would anyone please help me with this, if you have an alternative way of getting the player’s outfit ids would you kindly please tell me, thank you.

3 Likes

Hi there, in order to achieve this, you can do something along the lines of the below code, which should help you get moving in the right direction. However, I’d highly recommend reading the documentation on AvatarEditorService to familiarize yourself with the service’s functions/events and what they return.

The below code starts off by firstly prompting the LocalPlayer to grant/deny permission to their inventory’s ReadAccess. If granted, the GetOutfits() returns an OutfitPages Instance, which can then be used to iterate through it’s available pages in a loop, which is exactly what the getAllOutfits function does. It’ll iterate through all the pages until it has processed the last page and populates the outfitIds array with all available editable player-saved outfits. You can further implement methods such as GetOutfitDetails() if you wish to further process the outfitId or get it’s details.

Hope that helps. Good luck!

-- LocalScript

local plr = game:GetService("Players").LocalPlayer
local AvatarEditorService = game:GetService("AvatarEditorService")

local Permission = false
local outfitIds = {}

task.wait(1)

local function promptPermission()
	AvatarEditorService:PromptAllowInventoryReadAccess()

	Permission = AvatarEditorService.PromptAllowInventoryReadAccessCompleted:Wait()
end

local function getAllOutfits(outfitPage)	
	while not outfitPage.IsFinished do
		if Permission == Enum.AvatarPromptResult.Success then
			for _, outfit in ipairs(outfitPage:GetCurrentPage()) do
				if outfit["IsEditable"] then
					table.insert(outfitIds, outfit["Id"])
				end
			end
			
			task.wait()
			
			if not outfitPage.IsFinished then
				outfitPage:AdvanceToNextPageAsync()
			end
		end
	end
end

promptPermission()

if Permission == Enum.AvatarPromptResult.Success then
	getAllOutfits(AvatarEditorService:GetOutfits())
	print(outfitIds)
end
5 Likes

Hi, I tried it and it works! Thanks for helping!

by the way, is there a limit to getting the outfits of the players? Cause it seems like it does not load all of the player’s outfits

Sorry, had a minor little mistake in the code where I had an extra AdvanceToNextPageAsync() function call where it wasn’t supposed to be.

I’ve edited the post again and the function should now return all outfits correctly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.