I’m trying to hide an error from always showing up. Basically, I’m trying to make a whitelisting system.
So… The following error keeps popping up:
MarketplaceService:GetProductInfo() argument is not a valid assetId (supplied assetId was less than 0)
I do know that it will work once the game is published. BUT… there’s the problem. It always shows up once it hasn’t been published. What I’ve tried to do is to delete the file when it hasn’t got any actual placeID for it. It will delete itself but it still manages to bring up the error. The line causing it is this:
local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(PlaceId)
I just can’t find a way on how to disable the error from popping up. I’m trying to sell one of my products.
Basically… a solution I was thinking about is like delaying the line until everything gets destroyied. I can’t manage to figure out how to do it on my own. Need your help, fellas.
The PlaceId is 0 when you aren’t testing an actual place uploaded to ROBLOX, but rather a local place file on your computer. As @ahmettrPro2 mentioned, it is also a good idea to wrap the call in a protected call.
local MarketplaceService = game:GetService("MarketplaceService")
function GetProductInfo(AssetId)
local Success, Result = pcall(MarketplaceService.GetProductInfo, MarketplaceService, AssetId)
if Success then
return Result
else
print("Unable to get product-info for " .. AssetId .. " - " .. Result)
return {}
end
end
You will be able to call the GetProductInfo function without breaking your script.
When you use the pcall function, the first parameter is is the function, and from there on you can add parameters.
function MyFunction(Message)
print(Message)
end
local Success, Result = pcall(MyFunction, "Hello world!")
-- Hello world!
That’s what I was basically doing in my code. except I put MarketplaceService in the first argument, which is because the GetProductInfo method must be called with the : operator, which passes MarketplaceService as the true first parameter.
local MyTable = {}
MyTable.Number = 100
function MyTable.PrintNumber(MyTable)
print(MyTable.Number)
end
MyTable:PrintNumber() -- just MyTable.PrintNumber(MyTable)