Issues with :PlayerOwnsAsset

An error in my script keeps showing up; giving me " (Bad Request) " even though I don’t know what I’m doing incorrectly. The script runs through fine as it runs through all the values and gives the total value at the end. However, :PlayerOwnsAsset() is the part that is penalizing the rest of the script.

The purpose of the script is to run through all the ID’s and check to see if the player owns that asset (this is shirts, t-shirts, and pants only); how am I suppose to organize the code for it to work properly?

function ClothingVerification()
	local Players = game:GetService("Players").LocalPlayer
	local Assets = {5001890347, 5001891887, 3570551691, 5152114157, 5152115916}
	local Total = 0
	
	for i, value in pairs (Assets) do 
		if game:GetService("MarketplaceService"):PlayerOwnsAsset(Players, i) then
			print(value)
			Total = Total + 1 
			print("Sucessful")
		else
			print("Don't Have")
			print(value)
		end 
	end
	
	print(Total)
	
end 

The Output
image

Thank you in advanced for helping.

3 Likes

PlayerOwnsAsset will not work anymore its deprecated try looking here

I’m looking for Shirt, T-Shirt, and Pants ID checks. Not Gamepass checks. Does that mean Lua doesn’t compensate this function anymore?

try doing this on the server not the client use a remote event to do this i thought this was a gamepass for a second sorry

It means that the Id is invalid.

I agree you should fire an asset check event from the client to the server, check when you player joins (.PlayerAdded) or when the character is added (.CharacterAdded). Second, your for loop should be this anyways.

for i, assetId in pairs(Assets) do
    if game:GetService("MarketPlaceService"):PlayerOwnsAsset(Players, assetId) then
        -- You were checking the index of Assets not the actual AssetId
        print(assetId)
        Total += 1
        print("Successful")
    else
        print(assetId)
        print("Don't have")
    end
end
1 Like

Nice, thank you.

I’ll need to make it a RemoteFunction since I have to return information after back onto a GUI. Though, that is besides the point.

In that case ignore the first sentence, but I believe that code should work. I’m just doing it off the top of my head.