Small mistake for Code Sample in MarketPlaceService Documentation

At MarketplaceService:PlayerOwnsAsset(), the code sample is incorrect.

In case MarketplaceService:PlayerOwnsAsset() throws an error, doesPlayerOwnAsset will return a string and not a boolean, without an extra check on _success, this code will think someone owns the asset whenever PlayerOwnsAsset fails to execute properly. This may not be the desired behaviour.

A solution would be changing if doesPlayerOwnAsset then to if _success and doesPlayerOwnAsset then as that is likely the desired behavour.

Another solution is handling it differently, such as adding the following:

if not _success then
    print("PlayerOwnsAsset call failed: ", doesPlayerOwnAsset)
    return
end
2 Likes

Now that the docs are open source, you can create a pull request with your suggestions.

If you don’t want to, I can submit a PR on your behalf.

2 Likes

Thanks for the report! We’ll follow up when we have an update for you.

1 Like

Referenced code samples are still closed source for now, but we’re working on changing that!

2 Likes

Great catch on this error. The code sample is now corrected!

2 Likes

Just noticed this, my bad!

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