Issue when checking if game owner owns a t-shirt

Hello, so I have a script that checks if the game’s owner owns a t-shirt. I get no error but it always responds as they don’t own the t-shirt even though they do. Can anyone help?
Here is my code:

local Players = game:GetService("Players")
local players = game.Players:GetChildren()
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset
local PlaceId = game.PlaceId
local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(PlaceId)
local gameOwner = nil
local ASSET_ID = 5647588072

if game.CreatorType == Enum.CreatorType.Group then
    gameOwner = game:GetService("GroupService"):GetGroupInfoAsync(PlaceInfo.Creator.CreatorTargetId).Owner.Id
else
    gameOwner = game.CreatorId
end

local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, gameOwner, ASSET_ID)

if success then
  print("They own it!")
end

success is if the function was successful or not. You should be checking doesPlayerOwnAsset as that is what the function returns.

Hello, I have replaced the success with doesPlayerOwnAsset and now it’s the reverse. It says that everyone owns the t-shirt even when they don’t. I really don’t understand it…

Can you post your current script?

local Players = game:GetService("Players")
local players = game.Players:GetChildren()
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset
local PlaceId = game.PlaceId
local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(PlaceId)
local gameOwner = nil
local ASSET_ID = 5647588072

if game.CreatorType == Enum.CreatorType.Group then
    gameOwner = game:GetService("GroupService"):GetGroupInfoAsync(PlaceInfo.Creator.CreatorTargetId).Owner.Id
else
    gameOwner = game.CreatorId
end

local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, gameOwner, ASSET_ID)

if doesPlayerOwnAsset then
  print("They own it!")
end

MarketplaceService:PlayerOwnsAsset() takes the player instance as the first argument, not UserId.

local Players = game:GetService(“Players”)
local players = game.Players:GetChildren()
local MarketplaceService = game:GetService(“MarketplaceService”)
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset
local PlaceId = game.PlaceId
local PlaceInfo = game:GetService(“MarketplaceService”):GetProductInfo(PlaceId)
local gameOwner = nil
local ASSET_ID = 5647588072

if game.CreatorType == Enum.CreatorType.Group then
gameOwner = game:GetService(“GroupService”):GetGroupInfoAsync(PlaceInfo.Creator.CreatorTargetId).Owner.Id
else
gameOwner = game.CreatorId
end

local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, gameOwner, 5647588072)

if doesPlayerOwnAsset then
print(“They own it!”)
try this?

Please put your code in a code block. Also, can you explain what you modified?

Yes I know, that line is used to get the creator’s ID when it is a group owned game.

You can not use UserId for MarketplaceService:PlayerOwnsAsset().

It uses the place’s ID not the UserId for MarketplaceService:GetProductInfo()

Sorry, it was a typo, I meant PlayerOwnsAsset.

Oh, I have to use the Player Object then? If so, how would I get the Player Object of a player that isn’t in the game?

You can not, but you can use a game pass instead of a T-Shirt and use MarketplaceService:UserOwnsGamePassAsync() which accepts UserIds.

1 Like

Ugh, that’s annoying. Thank you for your help though!

1 Like