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
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.
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.
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).
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
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.