I want help checking if a player owns a asset

I want my code to check if the Player owns an asset when they click a Text Button.

local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset

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

script.Parent.MouseButton1Click:Connect(function()
	if doesPlayerOwnAsset then
		print("rich")
	else 
		print("poor")
	end
end)

LargeHotDogs13

local Button = script.Parent

local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset

local Succ, Res = pcall(PlayerOwnsAsset, MarketplaceService, Player, ASSET_ID)

if Succ then
	Button.MouseButton1Click:Connect(function()
		if Res then
			print("rich")
		else 
			print("poor")
		end
	end)
else
	print("API request failed.")
end

You just forgot to declare the player instance, also if “Succ” is false then the API request has failed.

1 Like

I think you are forgetting about the LocalPlayer part of the script (which you left as just player)

local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset

local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, Players.LocalPlayer, ASSET_ID)

script.Parent.MouseButton1Click:Connect(function()
	if doesPlayerOwnAsset then
		print("rich")
	else 
		print("poor")
	end
end)
1 Like