UserOwnsGamePassAsync returning nil in studio

This is the problem:

if GamepassTemplate[gamepass] ~= nil then
	print(GamepassTemplate[gamepass])
	local s, r = pcall(function()
		local owned = Marketplace:UserOwnsGamePassAsync(player.UserId, GamepassTemplate[gamepass])
		print(owned)
		return owned
	end)
	print(s, r)
	if s and r then
		print('player owns gamepass with id of '.. gamepass)
		return true
	end
end

image

this is returning nil, and its not printing that the player owns the gamepass.
The output is it after purchasing, and trying again meaning that “r” should be true but it prints false

1 Like

Can we see the rest of the code? That’ll allow us to help you debug :slight_smile:

1 Like
function MarketplaceService:OwnsGamepass(player:Player, gamepass)
	local DataService = Knit.GetService('DataService')
	
	if GamepassTemplate[gamepass] ~= nil then
		print(GamepassTemplate[gamepass])
		local s, r = pcall(function()
			local owned = Marketplace:UserOwnsGamePassAsync(player.UserId, GamepassTemplate[gamepass])
			print(owned)
			return owned
		end)
		print(s, r)
		if s and r then
			print('player owns gamepass with id of '.. gamepass)
			return true
		end
	end
end

local VIP = MarketplaceService:OwnsGamepass('VIP')
I am using the Knit Framework. I think this is all the important code.
Marketplace is the marketplace service

I see that I didnt give much detail here, so here is the entire script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Marketplace = game:GetService('MarketplaceService')

local Packages = ReplicatedStorage.Packages

local Knit = require(Packages.Knit)
local GamepassTemplate = require(ReplicatedStorage.Templates.GamepassTemplate)

local MarketplaceService = Knit.CreateService{
	Name = 'MarketplaceService',
	Client = {}
}

local function ReverseSearch(gamepass)
	for i, v in GamepassTemplate do
		if v == gamepass then
			return i
		end
	end
end

function MarketplaceService:KnitStart()
	local DataService = Knit.GetService('DataService')
	
	Marketplace.PromptGamePassPurchaseFinished:Connect(function(player, gamepass, purchased)
		if purchased == true  then
			DataService:SetValue(player, ReverseSearch(gamepass), purchased)
		end
	end)
	
end

function MarketplaceService:PromptGamepass(player, gamepass)
	if GamepassTemplate[gamepass] ~= nil then
		Marketplace:PromptGamePassPurchase(player, GamepassTemplate[gamepass])
	end
end

function MarketplaceService:OwnsGamepass(player:Player, gamepass)
	local DataService = Knit.GetService('DataService')
	
	if GamepassTemplate[gamepass] ~= nil then
		print(GamepassTemplate[gamepass])
		local s, r = pcall(function()
			local owned = Marketplace:UserOwnsGamePassAsync(player.UserId, GamepassTemplate[gamepass])
			print(owned)
			return owned
		end)
		print(s, r)
		if s and r then
			print('player owns gamepass with id of '.. gamepass)
			return true
		end
	end
end

function MarketplaceService.Client:PromptGamepass(player, gamepass)
	return self.Server:PromptGamepass(player, gamepass)
end

function MarketplaceService.Client:OwnsGamepass(player, gamepass)
	return self.Server:OwnsGamepass(player, gamepass)
end

return MarketplaceService

Is Studio Acess to API Services enabled in your game settings?

Yes, the gamepass id and userid is correct, and everything is enabled.

After the r variable in the pcall, add “, e” and try printing that. That will be the error message, and it will tell you what went wrong. But since success is true, it will probably just be nil.

I just did that and it prints out nil.
I dont think there is something wrong with the code inside the pcall.
If there was something wrong with it then “owned” would’ve been nil but it returns false. I think that the problem may be on the knit server, because all I’m doing for knit is:

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local Packages = ReplicatedStorage.Packages

local Knit = require(Packages.Knit)

Knit.AddServicesDeep(script.Services)

Knit.Start():andThen(function()
	print('Knit started on server')
end):catch(warn)

I’m not sure if this could be causing it. Also when I print out purchased after the PromptGamePassPurchaseFinished it prints out true. Mayb that’s important information

I’m not familiar with Knit, so I have no idea if it could be doing anything weird or not.