PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

PlayerOwnsAsset

Returns whether the inventory of given Player contains an asset, given the ID. This method can query for hats, models, sounds, etc. This function takes a small amount of time to send a request the Roblox website.

In the case that a query fails, this function will throw an error. Therefore, it is recommended to wrap calls to this function in pcall.

  • This method should not be used for game passes, since they use a separate ID system. Legacy game passes that still depend on an asset ID should use GamePassService/PlayerHasPass instead of this method.
  • This method cannot be used to check for developer products since they can be purchased multiple times but not owned themselves. Use a GlobalDataStore to save when a developer has bought a developer product instead.

Parameters

Name Type Default Description

A Player object whose inventory shall be tested for the ownership of the given asset

The ID of an asset for which the given player’s inventory shall be tested

Returns

Return Type Summary

Indicates whether the given Player’s inventory contains the given asset


Code Samples


Check for Item Ownership

This code sample demonstrates how to check if a player owns a certain item. Here, we’re checking for the item Midnight Shades, a hat that costs R$ 250. As a player enters the game, their account is checked for the ownership of that item and a message is printed.

Notice how the call to PlayerOwnsAsset is wrapped in pcall - this prevents the code from throwing an error in case the player’s inventory can’t be checked for some reason. Should such an error occur, the success variable would be false.