How do I pick a random item (hats, shirts, pants, etc) from a player’s inventory?
By inventory do you mean Player.Backpack or ANYTHING under player character model?
no like anything in player’s profile inventory like all their hats and stuff
game.Players.ChildAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local stuff = char:GetChildren()
local randomizer = stuff[math.random(1, #stuff)]
print(randomizer)
try this and see if it’ll work.
no not like that like that like anything from here
![]()
oooh then you have to use the roblox api for that.
well yeah I know that i was looking into it, but how would I go about doing it
1 Like
This will only go through the first page of accessories (first 100), but this should work:
local HTTP = game:GetService("HttpService")
local assettypes = {
"Pants",
"Shirt",
"Hat",
"Face",
"Gear",
"Place",
"Audio",
"Face",
"Package",
"Animation",
"Torso",
"RightArm",
"LeftArm",
"LeftLeg",
"RightLeg",
"HairAccessory",
"FaceAccessory",
"NeckAccessory",
"ShoulderAccessory",
"FrontAccessory",
"BackAccessory",
"WaistAccessory",
"EmoteAnimation",
"Video",
"JacketAccessory",
"SweaterAccessory",
"ShortsAccessory",
"LeftShoeAccessory",
"RightShoeAccessory",
"DressSkirtAccessory"
}
local assetlist = table.concat(assettypes, ",")
game.Players.PlayerAdded:Connect(function(plr)
local data = HTTP:GetAsync("https://inventory.roproxy.com/v2/users/"..plr.UserId.."/inventory?assetTypes="..assetlist.."&itemsPerPage=100",true)
data = HTTP:JSONDecode(data)
if #data.data > 0 then
local randomaccessory = data.data[math.random(#data.data)]
print(randomaccessory)
end
end)
Also, if it errors and says “HTTP 403 (Forbidden)” then the users inventory is privated.
1 Like