Hi guys, i was just wondering if anyone knows how “Equip Avatar with Items” works as u can see in the screenshot. I know its possible since a lot of catalog games have done it, for example: Catalog Avatar Creator. It basically lets you equip/update ur roblox avatar with some accessories u own
2 Likes
You need to prompt the user to allow access to their inventory at the beginning of the session. This is done using the PromptAllowInventoryReadAccess()
method. You will need to create a GUI that displays the items from the user’s inventory and allows them to select which items to equip.
local AvatarEditorService = game:GetService("AvatarEditorService")
-- Prompt the user for inventory access
AvatarEditorService:PromptAllowInventoryReadAccess()
-- Wait for the user's response
local result = AvatarEditorService.PromptAllowInventoryReadAccessCompleted:Wait()
if result == Enum.AvatarPromptResult.Success then
-- Access granted, proceed with reading the inventory
print("Inventory access granted!")
else
-- Handle the case where access was not granted
print("Inventory access denied.")
end
Once you have access, you can read the user’s inventory to get a list of items they own.
local AvatarEditorService = game:GetService("AvatarEditorService")
local assetTypes = {
Enum.AvatarAssetType.BackAccessory,
Enum.AvatarAssetType.ShoulderAccessory,
Enum.AvatarAssetType.WaistAccessory,
-- Add other asset types as needed
}
local pagesObject = AvatarEditorService:GetInventory(assetTypes)
local currentPage = pagesObject:GetCurrentPage()
for _, item in currentPage do
print(item)
end
After reading the user’s inventory, you can equip the items they select. To save the current avatar configuration, you use the PromptSaveAvatar()
method.
local AvatarEditorService = game:GetService("AvatarEditorService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Get the current HumanoidDescription
local currentDescription = humanoid:GetAppliedDescription()
-- Save the current avatar configuration
AvatarEditorService:PromptSaveAvatar(currentDescription, humanoid.RigType)
local result = AvatarEditorService.PromptSaveAvatarCompleted:Wait()
if result == Enum.AvatarPromptResult.Success then
-- Avatar saved successfully
print("Avatar saved!")
else
-- Handle the case where saving the avatar failed
print("Failed to save avatar.")
end
You can find out more information in the docs.
2 Likes
Thanks a lot! I think i get it now
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.