An error what I don't know how to hide

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.

2 Likes

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.

2 Likes

Use a pcall. pcalls do not pump out errors and will not terminate the script. Here’s the pcall version:

local PlaceInfo = nil
local success, err = pcall(function()
    PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(PlaceId)
end)
2 Likes

Seems interesting. Never knew about them and have never used them. Will give them a look. :slight_smile:

Perhaps it would be better to make this a function, so that it could be called more than one time?
(Your solution works just fine, though.)

2 Likes

Holy cow. Everything seems so complicated to me. xD
I basically know nothing, tbh. I know some of the most basic things.

Do you know any good and quick tutorials what could give me a good startup at learning LUA code?

1 Like

OoOo… Seems interesting. Gonna check that out. :wink:

I can break things down for you.

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)
1 Like