Turn players HumanoidDescription accessories into values

I basically am trying to get all the players HumanoidDescription accessories and turn them into Values (so I can then store and change them using DataStore2)

Problem is they are strings, not tables :grimacing:

Basically, if the players roleplay name is nothing (meaning they don’t have a previous data save) I have to set up their data values using their default Roblox character. It’s easy with shirts, pants, and faces, as they can only have 1 on (so simply setting the value of each data point to their HumanoidDescription counter part is easy) However, accessories are much harder

-- Loading character
if PlayerData.Character['Roleplay Name'].Value == '' then
	-- No previous data
	PlayerData.Character['Roleplay Name'].Value = player.Name
	
	PlayerData.Character.Face.Value = humanoidDescription.Face
	PlayerData.Character.Shirt.Value = humanoidDescription.Shirt
	PlayerData.Character.Pants.Value = humanoidDescription.Pants
	
	-- Set default accessories
	for _, v in pairs(humanoidDescription.HatAccessory) do
		print(v)
        -- Create a StringValue (Name == Accessory name, Value == Accessory ID)
	end
end

Obviously it errors on the for loop as HatAccessory is a string, and not a table, however I don’t know how else I could accomplish this :confused:

And since the accessories are folders inside the player (not values like Shirt, Face, Pants) means I have to create new values for each item.

1 Like

For accessories given the information on the Wiki, their data type and the way they are formatted, you will need only one thing: to split the string with a comma as a delimiter. That will automatically create an array for you. You will not be able to get accessory names though, only ids, so unless you intend to use the accessory type as the ValueObject’s name then you’re in a pickle as far as that goes.

for _, id in ipairs(humanoidDescription.HatAccessory:split(",")) do
    print("HatAccessory:", id)
end
2 Likes

I don’t really need the accessory type as the name, as they get paretented to a folder of the accessory type. As for naming, can’t I just use MarketplaceService:GetProductInfo() and then just .Name??

You could, yeah. It’ll give you actual name of the asset from the catalog (which, it should be noted, is not the same as the instance name when it’s added to your character) if that’s okay. Just be wary of limitations and all - I’m pretty sure there’s an undocumented call limit for GetProductInfo per minute. You’re all set otherwise.

1 Like