:UserOwnsGamepassAsync() is not working

I am making a script that lets a user purchase multiple gamepasses from a shop. Other scripts prompt the purchase fine but the script linked does not give the player the item. I used print statements to root out the problem and found it was the :UserOwnsGamepassAsync(). I have no idea what is wrong with it. Please help!

local marketPlaceService = game:GetService("MarketplaceService")

local rainbowTitleId = 14279002
local balloonId = 14280017
local segwayId = 14280023
local vipId = 14280028

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if marketPlaceService:UserOwnsGamePassAsync(player.UserId, rainbowTitleId) then
			game.ServerStorage:WaitForChild("OverheadGui"):Clone().Parent = character:WaitForChild("Head")
		end
		
		if marketPlaceService:UserOwnsGamePassAsync(player.UserId, balloonId) then
			game.ServerStorage:WaitForChild("GreenBalloon"):Clone().Parent = player:WaitForChild("Backpack")
			game.ServerStorage:WaitForChild("GreenBalloon"):Clone().Parent = player:WaitForChild("StarterGear")
		end
		
		if marketPlaceService:UserOwnsGamePassAsync(player.UserId, segwayId) then
			game.ServerStorage:WaitForChild("HandlessSegway"):Clone().Parent = player:WaitForChild("Backpack")
			game.ServerStorage:WaitForChild("HandlessSegway"):Clone().Parent = player:WaitForChild("StarterGear")
		end
	end)
end)

You need pcall()

Use this:

local marketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local rainbowTitleId = 14279002
local balloonId = 14280017
local segwayId = 14280023
local vipId = 14280028

function UserOwnsGamePassAsync(PlayerID,GamePass)
    local Success,Results = pcall(function()
    	return marketPlaceService:UserOwnsGamePassAsync(PlayerID,GamePass)
	end)
    print(Success,Results)
	if Success and Results then
    	return true
	end
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
    	if UserOwnsGamePassAsync(player.UserId,rainbowTitleId) then
    		ServerStorage:WaitForChild("OverheadGui"):Clone().Parent = character:WaitForChild("Head")
		end
		if UserOwnsGamePassAsync(player.UserId, balloonId) then
    		ServerStorage:WaitForChild("GreenBalloon"):Clone().Parent = player:WaitForChild("Backpack")
    		ServerStorage:WaitForChild("GreenBalloon"):Clone().Parent = player:WaitForChild("StarterGear")
	    end
		if UserOwnsGamePassAsync(player.UserId, segwayId) then
    		ServerStorage:WaitForChild("HandlessSegway"):Clone().Parent = player:WaitForChild("Backpack")
	    	ServerStorage:WaitForChild("HandlessSegway"):Clone().Parent = player:WaitForChild("StarterGear")
	    end
    end)
end)

where do i put the function in the script?

In ServerScriptService or in the same script you provided.

the function UserOwnsGamePassAsync, not the script

Just replace the script if you don’t have something underneath.

no no no no no, you made a function called UserOwnsAssetAsync(), where do you put that function? im not talking about the script im talking about the function you used a pcall in

do you get what I mean by that?

Ehh … on top of this:

Players.PlayerAdded:Connect(function(player)

your not getting me.

where do you call the function in the script like this:

game.Players.PlayerAdded:Connect(function(player)
funcName()
end)

put pcall when player is added.

ive never used mps im actually rlly confused rn! i dont know what to do

all these words arnt making sense to me lol

Just replace the script, the Id’s don’t change it xd

this script didnt work btw forgot to say @SOTR654

Replace your code with @SOTR654’s code.

i did that, thats the script that i said didnt work

Does that person own’s the gamepass?

1 Like

the person is me, i made the gamepasses so yes i own then

and i dont actually OWN them in my inventory as i deleted them from it