MarketPlaceService Assisstance

The following code is a snippet of a function to create an NPC in my Roblox game. I am currently experiencing an issue where a deleted shirt/pant is making its way through and applying on the NPC (torso/legs are skin colored, so I know its a deleted item that’s on the NPC).

In reality, this code should detect if a Shirt/Pant/Hat/Hair is deleted, and re-try until it is not deleted. If you have any questions feel free to ask.

ServerScript:

local MarketplaceService = game:GetService("MarketplaceService")
local function CloneItem(GivenItem)
	local ChosenItem
	local ChosenItemSave
	local ChosenItemName

	repeat wait()
		ChosenItem = GivenItem[math.random(#GivenItem)]
		if ChosenItem then
			ChosenItemSave = ChosenItem
			ChosenItemName = ChosenItemSave.Name

			if ChosenItem.Parent.Name == "Shirts" then
				ChosenItem = ChosenItem.ShirtTemplate
			elseif ChosenItem.Parent.Name == "Pants" then
				ChosenItem = ChosenItem.PantsTemplate
			elseif ChosenItem.Parent.Name == "Hairs" or ChosenItem.Parent.Name == "Hats" then
				if ChosenItem.Handle:FindFirstChild("SpecialMesh") then
					ChosenItem = ChosenItem.Handle.SpecialMesh.MeshId
				elseif ChosenItem.Handle:FindFirstChild("Mesh") then
					ChosenItem = ChosenItem.Handle.Mesh.MeshId
				end
			end
			ChosenItem = string.match(ChosenItem, "%d+")

			if MarketplaceService:GetProductInfo(ChosenItem) then
				ChosenItemSave:Clone().Parent = NewNPC
			else
				warn("The item: "..ChosenItemName.." has been deleted from the Marketplace! Contact a developer to have them fix this.")
			end
		else
			warn("No valid item found in GivenItem.")
		end
	until ChosenItem
end
for _, Shirt in pairs({Shirts:GetChildren()}) do
	CloneItem(Shirt)
end
for _, Pant in pairs({Pants:GetChildren()}) do
	CloneItem(Pant)
end
for _, Hair in pairs({Hairs:GetChildren()}) do
	CloneItem(Hair)
end
for _, Hat in pairs({Hats:GetChildren()}) do
	CloneItem(Hat)
end

If I am not mistaken CloneItem(Shirt) is not sending a table as the arg and you are treating that arg as a table in your function.

What do you actually mean by this? Everything is working here except for the fact that it’s not detecting if its a deleted item

Ah okay I misunderstood and made a mistake myself xD

Does anyone know how to solve this?