Detecting if a shirt has been deleted or not

Hey, for a while now I have been trying many ways, even resorting to AI to help me create this piece of code, but no luck.

In one of my games I use NPCs, and I have 20 shirts, and 20 possible pants for these NPCs. But recently having to go through 40 objects just isn’t ideal for me and I wanted to create a script that would just throw me a warning with the ShirtTemplate saying that it was deleted. This is because Roblox has been taking down shirts/pants, making my NPCs look… questionable.

Here’s what I have so far… and yes 1 shirt is actually deleted and the other is fine:

local HttpService = game:GetService("HttpService")

local function isAssetAvailable(assetURL)
    local success, response = pcall(function()
        return HttpService:GetAsync(assetURL)
    end)

    if success then
        return true
    else
        return false
    end
end

local shirtTemplateURL1 = "http://www.roblox.com/asset/?id=10398620764"
local shirtTemplateURL2 = "http://www.roblox.com/asset/?id=16354531169"

local isShirt1Available = isAssetAvailable(shirtTemplateURL1)
local isShirt2Available = isAssetAvailable(shirtTemplateURL2)

print("Shirt 1 available: ", isShirt1Available)
print("Shirt 2 available: ", isShirt2Available)

^^ Prints:

Shirt 1 available: false
Shirt 2 available: false

Also,
I have also tried something small like:

if MarketplaceService:GetProductInfo(ChosenItem) then
    ChosenItemSave:Clone().Parent = NewNPC
else
    warn("The item: "..ChosenItemName.." has been deleted from the Marketplace!")
end

^^ Does not work aswell

1 Like

If i’m not wrong, deleted stuff gets id “0”, so you may try to check, if your shirt has deleted id

1 Like

No the ShirtTemplate I have saved doesn’t ever change?

Maybe I should’ve explained better but I have each shirt and each pant as an Instance, and in my NPC code I just copy and paste the shirt/pant over to the NPC.

This means the ShirtTemplate/PantTemplates never change.

1 Like

Check for deleted id in a template, chosen by script, and make it delete the problematic template

1 Like

See I have already tried many things before making a post.

Can you show me an example of what you mean? Also hopefully someone will have an answer!

1 Like

Had problems also checking this (odd) …
Anyways this is kind of a working work around.

assetID=4637618893
MarketplaceService=game:GetService("MarketplaceService")
asset=MarketplaceService:GetProductInfo(assetID)
length=string.len(asset.Description)

if length>0 then
	print(asset.Description)
else	
	print("no Description")
end

Make sure you have htttp requests turn on for the game.

2 Likes
If templateshirt.AssetId == "rbxasset://0" then
templateshirt:Destroy()
End

Thanks for the idea, but this didn’t work. Here’s what I have:

local MarketplaceService = game:GetService("MarketplaceService")
local TestingState = true

spawn(function()
	while TestingState == true do
		for _, Shirt in pairs({Shirts:GetChildren()}) do
			local ChosenShirt = Shirt[math.random(#Shirt)]
			local AssetID = MarketplaceService:GetProductInfo(string.match(ChosenShirt.ShirtTemplate, "%d+"))
			local TheLength = string.len(AssetID.Description)
			print(TheLength)
			
			if TheLength >= 1 then
				ChosenShirt:Clone().Parent = NewNPC
				TestingState = false
			end
		end
	end
end)

^ The above is wrapped in a spawn(function) because of the while x == true do, because this needs to loop will I have an undeleted shirt, and because I also need to check pants.

Irrelevant but this was my code beforehand:

for _, Shirt in pairs({Shirts:GetChildren()}) do
	local ChosenShirt = Shirt[math.random(#Shirt)]
	ChosenShirt:Clone().Parent = NewNPC
end

This didn’t work, as the deleted shirt printed 5 and the undeleted shirt printed 11, so this doesn’t work and my NPCs are still unclothed (only when deleted shirt is picked).

If anyone has an ideas let me know!!! Thanks.

the most basic way …

local HttpService = game:GetService("HttpService")

local function isItemGone(assetId)
    return not pcall(function()
        return HttpService:GetAsync("https://api.roblox.com/marketplace/productinfo?assetId=" .. assetId)
    end) or response == "null"
end

local shirtId = 123456
if isItemGone(shirtId) then
    warn("Shirt template missing from catalog: " .. shirtId)
end

local pantsId = 654321
if isItemGone(pantsId) then
    warn("Pants template missing from catalog: " .. pantsId)
end

1 Like

This is left over from running some test… That can be removed. It no longer has a purpose as a string. The return pcall should take care of it all as is.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.