UserOwnsGamePassAsync not Working

Hello, in my testing place I have 2 gamepasses that are from the main game.

These passes in the code are checked for via a function and an if statement, and if they own the gamepass the script unlocks items.

The problem here as some testers have noted that also own the gamepass, is it will not return true even though the player actually does own the pass.

Even more oddly, it works fine for me and unlocks it for me every time.

(Also note: the pcall doesnt return any errors that i’ve seen so far)

Here is the code:

local function ownsgamepass(userid,gamepassid)
	local s,res = pcall(marketPlaceService.UserOwnsGamePassAsync,marketPlaceService,userid,gamepassid)
	if not s then
		res = false
	end
	return res
end

local function checkGamepasses()
	if ownsgamepass(player.UserId,16825105) then
		print("OWNS GAMEPASS")
		setKyloRen(true)
	end
	if ownsgamepass(player.UserId,17833663) then
		print("OWNS GAMEPASS")
		setToySkin1(true)
	end
end

checkGamepasses()
1 Like

Is that the full script? Because if it isn’t you are missing this:
local marketPlaceService = game:GetService("MarketPlaceService")

1 Like

Tell your testers to rejoin the game after purchasing the gamepass as Roblox caches whether you own it or not.

That is earlier in the script, so yes that is indeed in the script

I did, and the results are the same. In fact some testers have it and some dont whichi is even stranger

Is this in a PlayerAdded event / in the player instance? And where is userid referenced.

1 Like

in a script inside starterGui, the script gets the player reference by using FindFirstAncesorWhichIsA(“Player”)

The player instance does work however so it isnt that

Are you sure you set the gamepassid to the right gamepass.

Yes absolutely positively sure that was the first thing testeds

Try:

    local function ownsgamepass(userid, gamepassid)
       local owns = false
       local s, res = pcall(function()
           owns = marketPlaceService:UserOwnsGamePassAsync(userid, gamepassid)
       end)

        if s and not res then
    		return owns
    	end
    	return res
    end

As it turns out nothing was wrong with my code. People were lying to get free gamepasses.

1 Like

The issue with your code was you used :UserOwnsGamepassAsync as a property… You typed “.” the solution changed the “.” to a “:”.