Current outfit getter

I was a bit bored so I made this outfit getter. Which will get the current outfit that the user is wearing.

The script:

local HttpService = game:GetService("HttpService")

local propertiesToCheck = {
	"Face",
	"Head",
	"LeftArm",
	"LeftLeg",
	"RightArm",
	"RightLeg",
	"Torso",
	"GraphicTShirt",
	"Shirt",
	"Pants",
	"BodyTypeScale",
	"DepthScale",
	"HeadScale",
	"HeightScale",
	"ProportionScale",
	"WidthScale"
}

local function isValid(t)
	local valid = false
	
	for _, v in pairs(t) do
		if v == false then
			valid = false
			return valid
		else
			valid = true
		end
	end
	
	return valid
end

game.Players.PlayerAdded:Connect(function(player)
	local userDescription = game.Players:GetHumanoidDescriptionFromUserId(player.UserId)
	
	local success, err = pcall(function()
		local request = HttpService:RequestAsync({
			Method = "GET",
			Url = string.format("https://avatar.roproxy.com/v1/users/%d/outfits?itemsPerPage=50", player.UserId)
		})
		
		local userOutfits = HttpService:JSONDecode(request.Body)
		local foundOutfit = false
		
		if userOutfits then
			userOutfits = userOutfits.data
			
			local startTime = tick()
			
			print("DEBUG: Starting search")
			for _, outfit in ipairs(userOutfits) do
				task.spawn(function() -- spawn a new thread to fast search
					
					local outfitId = outfit.id
					local outfitName = outfit.name
					assert(type(outfitId) == "number" or "stirng", "invalid outfit id")

					local outfitDescription = game.Players:GetHumanoidDescriptionFromOutfitId(outfitId)
					
					if outfitDescription then
						local matchingProps = {}

						for _, property in ipairs(propertiesToCheck) do
							local outfitProperty = outfitDescription[property]
							local userProperty = userDescription[property]

							if outfitProperty == userProperty then 
								
								matchingProps[property] = true
							else -- not matching
								matchingProps[property] = false
							end
						end

						if isValid(matchingProps) then
							foundOutfit = true
							local completedTime = tick() - startTime
							
							print(string.format("Found outfit! Outfit id: %d also known as: %s. Completed operation in %.2f", outfitId, outfitName, completedTime))
							return
						end
					end	
				end)
							
			end
		end	
	end)
	
	if not success then
		warn(string.format("Something went wrong: %s", err))
	end
end)


if u have any questions feel free to say so!

10 Likes