Hey guys - quick question. I’m trying to validate whether a given asset ID is valid or not, but I’m not sure which Service or function is the best for doing so. I could try preloading it with ContentProvider, but that seems weird to me. I could also try inserting it with InsertService, but I’m not sure it’s worth all the hassle of making a Model with it inside. I also want to validate that the asset ID refers to an image, and not a model or any other kind of asset.
Any ideas?
Don’t get me wrong either - if ContentProvider or InsertService are really the best options, I’m open to suggestions on using them too.
I mean you can try this but I’m sure there’s a better way possibly:
local Id = 123456
local Success = pcall(function()
game:GetService("MarketplaceService"):GetProductInfo(Id)
end)
if (Success) then
print("Valid AssetId")
else
print("Invalid AssetId")
end
local Marketplace = game:GetService("MarketplaceService")
--later
--method call replacement: a:b(...) == a.b(a, ...)
local valid = pcall(Marketplace.GetProductInfo, Marketplace, assetId)
--if valid then or if pcall(Marketplace.GetProductInfo, Marketplace, assetId) then
It’s not confusing. Functions are first-class. Also you can get the results of the function passed if there was no exception.
Something like:
local ok, info = pcall(MarketplaceService.GetProductInfo, MarketplaceService, asset)
-- info is the table or the string message if something went wrong
Thanks for your input, but please don’t either assume nor insult my intelligence and/or experience. I’ve been scripting for many years, I’ve just never come across this particular problem and was looking for a pointer in the correct direction. I know exactly what a pcall and functions do. These are great suggestions - I will try them out soon and come back with results.
userInput.TextBoxFocusReleased:Connect(function(EnterPressed)
if EnterPressed then
local newCursor = tonumber(searchBar.Text)
local succ = pcall(function()
game:GetService("MarketplaceService"):GetProductInfo(newCursor)
end)
if succ then
print('Success')
end
end
end)