How to get a users owned clothes?

I have been trying to find a way to look at a users inventory, and for a script to figure out how many clothing is owned by a specific group (In this case, the group that I own). I came across a post which was written sometime last year in seemed to have the answer, but after trying to figure it out I couldn’t. Here was the original post.

Easy way to get a user's owned clothes?

I have tried to take the sample of code and modify it in my own way, but simply can’t figure out what it does. Here is the code that I have tried:

local HttpService = game:GetService("HttpService")

local InventoryUrl = "https://robloxdevforumproxy.glitch.me/users/inventory/list-json?assetTypeId=11&cursor=&itemsPerPage=100&pageNumber=%x&sortOrder=Desc&userId=%i" -- used in a string.format thingy

-- In an event


game.Players.PlayerAdded:Connect(function(Player)
	local Inventory = HttpService:JSONDecode(HttpService:GetAsync(string.format(InventoryUrl, 1, Player.UserId))) -- function
	
	for _, item in next, Inventory do
		print(#item:GetChildren()) 
		
	end
end)

Most of the time the attemps that I have tried have done nothing, or just printed random numbers. Is there anyway around this or maybe a differens solution that would also work?

2 Likes

I’m trying to make a clothing purchase counter from group sales, so it displays how many they have purchased overall from both the game and group.

1 Like

You can’t :GetChildren of a table or boolean or whatever else is saved here, only actual Roblox Instances that are in the explorer. What are you trying to do here?

2 Likes

I know that this might not be too efficient, but you can try this post

See if a player owns an item

If you have less items in your group then you can do this but if you have a lot then it will be harder because you will have to see if they own each individual item

Then when you check add 1 to a variable, that you can maybe call clothingAmount or whatever you want, if they have the item

I know, it was just one of the things I tried to see what I was working with. I saw the code provided on another forum post but couldn’t quite figure out how to make it function with what I wanted to do. I have posted what I wanted to do in a comment on this post but when I get home I will change the original post.

I did see something about that, but when reading that it takes some time it deterred me as I have a lot of clothing items in my group, in the future it will contain even more I hope.

i think maybe you could use a for loop

Loop through all the Id’s that you can put in a table

I tried to use a for loop of the table as the output was a bool value and a table, but the table just printed out a variety of different numbers and more tables. I can give an example of what it prints out when I get home.

If you want to see how your table is formatted, you can print it using Repr or a similar tool (not sure if you’re using the beta output, but that works too). You should get a table formatted like this:

table
{
  "IsValid": true,
  "Data": {
    "TotalItems": null,
    "Start": 0,
    "End": 99,
    "Page": 1,
    "nextPageCursor": "25341277_1_71386e6935b0e520f235fb751c1dfe61",
    "previousPageCursor": null,
    "ItemsPerPage": 100,
    "PageType": "inventory",
    "Items": [
      {
        "AssetRestrictionIcon": {
          "TooltipText": null,
          "CssTag": null,
          "LoadAssetRestrictionIconCss": true,
          "HasTooltip": false
        },
        "Item": {
          "AssetId": 3683169622,
          "UniverseId": null,
          "Name": "Head Head Head Head Head Head Head Head Head",
          "AbsoluteUrl": "https://www.roblox.com/catalog/3683169622/Head-Head-Head-Head-Head-Head-Head-Head-Head",
          "AssetType": 11,
          "AssetTypeDisplayName": null,
          "AssetTypeFriendlyLabel": null,
          "Description": null,
          "Genres": null,
          "GearAttributes": null,
          "AssetCategory": 0,
          "CurrentVersionId": 0,
          "IsApproved": false,
          "LastUpdated": "/Date(-62135575200000)/",
          "LastUpdatedBy": null,
          "AudioUrl": null
        },
        "Creator": {
          "Id": 856623,
          "Name": "Trololo Team",
          "Type": 2,
          "CreatorProfileLink": "https://www.roblox.com/groups/856623"
        },
        "Product": {
          "Id": 0,
          "PriceInRobux": 5,
          "PremiumDiscountPercentage": null,
          "PremiumPriceInRobux": null,
          "IsForSale": true,
          "IsPublicDomain": false,
          "IsResellable": false,
          "IsLimited": false,
          "IsLimitedUnique": false,
          "SerialNumber": null,
          "IsRental": false,
          "RentalDurationInHours": 0,
          "BcRequirement": 0,
          "TotalPrivateSales": 0,
          "SellerId": 0,
          "SellerName": null,
          "LowestPrivateSaleUserAssetId": null,
          "IsXboxExclusiveItem": false,
          "OffsaleDeadline": null,
          "NoPriceText": null,
          "IsFree": false,
          "IsNewRobuxIconEnabled": false
        },
        "PrivateServer": null,
        "Thumbnail": {
          "Final": true,
          "Url": "https://tr.rbxcdn.com/6dbff0c4fba80be0e2f6cb45c892b0c9/110/110/Shirt/Png",
          "RetryUrl": "",
          "IsApproved": false
        },
        "UserItem": {
          "UserAsset": null,
          "IsItemOwned": false,
          "ItemOwnedCount": 0,
          "IsRentalExpired": false,
          "IsItemCurrentlyRented": false,
          "CanUserBuyItem": false,
          "RentalExpireTime": null,
          "CanUserRentItem": false
        }
      }, -- etc, the above dict repeats.
}

Looping through Items is probably what you want, since it’s an array of dictionaries for each item.

4 Likes

I’ll do this when I get home, didn’t know Repr was a thing. I’ll get back to you with what it prints out.

3 Likes

This is also a new beta feature (to print out tables without using repr)

Here’s a video

New Output

1 Like

Yeah, that’s what I was referring to when I said the beta output works too. It has a couple reliability issues where print will throw errors, though, so some people may not be comfortable making the switch just yet.

3 Likes

When using the Repr function and printing out the table, (script below) I got a long list of items (Which I assume to be items from my group) which I struggled to read due to the format being more like an essay than a table.

Screenshot https://gyazo.com/d95daa42ab1755ca054200c8a3708e2d

I looped through ‘Inventory’ using a for loop and printed out the result (Item)

-- // services // --
local HttpService = game:GetService("HttpService")

-- // variables // --
local InventoryUrl = "https://robloxdevforumproxy.glitch.me/users/inventory/list-json?assetTypeId=11&cursor=&itemsPerPage=100&pageNumber=%x&sortOrder=Desc&userId=%i" -- used in a string.format thingy
local repr = require(3148021300)

-- // events // --
game.Players.PlayerAdded:Connect(function(Player)
	local Inventory = HttpService:JSONDecode(HttpService:GetAsync(string.format(InventoryUrl, 1, Player.UserId))) -- function
	
	
	for _, item in pairs(Inventory) do
		print(repr(item))
	end
end)

The thing that I am stuck on now is this would be any use to me, and for it to do what I needed.

I can confirm that these are items and it is going through my inventory, but how would I use this to find out who owns the clothing and whether they’re coming from the group itself.

Oh yeah, you’ll definitely want to use the pretty print argument for that. That’s an absolute brick of text. What you’re probably looking for is Inventory.Data.Items, though, which is an array of dictionaries, and each dictionary contains information on one item.

2 Likes

I did have a look to see if anything came of use, and whether this would be anything I’m not too sure. I’m just not sure how I would use this to add to a variable with the amount of clothing from Lion Clothing that they own.

https://gyazo.com/eb796f11559b20fa463d7e68b3380b9b

Also, the last time I used the generic print I looped through and printed out ‘Item’ and it just gave me a list of different tables and variables which I had no idea of what the uses were.

Below is what happens when I simply print out ‘Item’ from the for loop previously.

https://gyazo.com/396b94bca4ba6911bb50029fab2bcbc8

If I then use another for loop on ‘Item’ (because of the table), I get this.

https://gyazo.com/cc0162e59179a1a3ae64fdc81fa947a0

I’ll try and use the roblox beta program print and see if that gives me anything more useful.

Sorry to message again, but using the beta program I managed to expand the table. I’m not the best at using tables, so how would I access who created each item from what I have?

https://gyazo.com/be24a350481b2b09e8c3dfb4413150fc

I just did print(Item) after it was looping through to get this.

Iterate through Inventory.Data.Items, and for each item check if the Creator.Id is 6484038 (the id for your group).
image
Something like this should give a general idea of how it’s structured:

for i, item in pairs(Inventory.Data.Items) do
	print(item.Creator.Name, item.Creator.Name) --> 6484038, Lion Clothing.
end
8 Likes