This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
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
- 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/PlayerHasPassinstead 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
GlobalDataStoreto save when a developer has bought a developer product instead.
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
Indicates whether the given Player’s inventory contains the given asset
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.
-- The item we're checking for: https://www.roblox.com/catalog/30331986/Midnight-Shades local ASSET_ID = 30331986 local ASSET_NAME = "Midnight Shades" local Players = game:GetService("Players") local MarketplaceService = game:GetService("MarketplaceService") local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset Players.PlayerAdded:Connect(function (player) local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, ASSET_ID) if doesPlayerOwnAsset then print(player.Name .. " owns " .. ASSET_NAME) else print(player.Name .. " doesn't own " .. ASSET_NAME) end end)