UserOwnsGamePassAsync Always returning true?

Ok So I’m trying to make a couple of 2x gamepasses. After testing, I realized that everyone was starting off with the 2x gamepasses even without buying it. I made a brand new Roblox account to test. On the storepage, it prompts him to purchase the gamepasses, so he should have nothing. But once i enter my game, he has the game passes. I made a button to test the results of UserOwnsGamePassAsync and it is returning true. There’s alot of code, So I’ll post the important ones.

 local phas2xCoinPass = Instance.new("BoolValue")
	phas2xCoinPass.Name = "has2xCoinPass"
	phas2xCoinPass.Value =  false
	phas2xCoinPass.Parent = PlayerVars

	local phas2xExpPass = Instance.new("BoolValue")
	phas2xExpPass.Name = "has2xExpPass"
	phas2xExpPass.Value = false
	phas2xExpPass.Parent = PlayerVars

	local phas2xSkillPass = Instance.new("BoolValue")
	phas2xSkillPass.Name = "has2xSkillPass"
	phas2xSkillPass.Value = false
	phas2xSkillPass.Parent = PlayerVars

	local phas2xGemPass = Instance.new("BoolValue")
	phas2xGemPass.Name = "has2xGemPass"
	phas2xGemPass.Value = false
	phas2xGemPass.Parent = PlayerVars
	
	local phas2xHealthPass = Instance.new("BoolValue")
	phas2xHealthPass.Name = "has2xHealthPass"
	phas2xHealthPass.Value = false
	phas2xHealthPass.Parent = PlayerVars
	
	phas2xCoinPass.Value =  UserOwnsGamePassAsync(player.UserId, 22504732)
	phas2xExpPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 22504770)
	phas2xSkillPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 22540149)
	phas2xGemPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 22504785)
	phas2xHealthPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 22691775)

I was testing if pcall made a difference, thats why there’s one with it and the rest without. Here’s my pcall function

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

Here’s the prompt to purchase, just incase theres something wrong there. But I like, my tests have the player start witht he game passes even without touching the prompt

local gamepassID = 22504732

script.Parent.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,gamepassID)
	
	
end)

Any help would greatly be appreciated. Thanks!

1 Like

I’m not sure, but I believe the Results variable on the call is the error that will be thrown if the pcall fails. Try removing the Results from the if statement after the pcall

1 Like

change return true to return result

change if success and result then to if success then

Unfortunately, that didn’t make a difference

It’s still returning true. And yes, I’m testing the results on my brand new accoutn that has nothing on it

Can you show us the updated code?

function UserOwnsGamePassAsyncM(PlayerID,GamePass)
	local Success = pcall(function()
		return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PlayerID,GamePass)
	end)
	print(Success)
	if Success then
		return 
	end
end

I removed the “results” variable and I renamed the pcall function just to make sure it doesn’t interfere with the actual UserOwnsGamePassAsync. Whats weird is that I have gamepasses with Tools and they work fine. Its only my 2x Gamepasses that are doing this

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

is what I’m using to call the player. Also the script is in ServerScriptService. It is the first script that runs when that game is loaded

function UserOwnsGamePassAsync(PlayerID,GamePass)
	local Success, Result = pcall(function()
		return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PlayerID,GamePass)
	end)
	print(Success)
	if Success and Result == true then
		return Result
	end
end

This should work just fine

Didn’t change a thing, everything is still returning true

Here is an example that should work, Roblox made it:

What they did was make a variable outside the pcall and set the variable inside the pcall with the results.

I don’t know if my explanation is correct, but when using a wrapped call of a function with the intention of getting the result of methods within the pcall, perhaps creating an upvalue within the UserOwnsGamePassAsync function and then setting it if the game pass check succeeds to that upvalue as listed below:

function UserOwnsGamePassAsync(PlayerID,GamePass)
	local ownsPass; -- Make sure that this variable represents the result of the gamepass check, NOT Success OR err ----
	local Success,err = pcall(function()
		ownsPass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PlayerID,GamePass)
	end)
	
	if Success then
		return ownsPass --- Return the result of the variable
	else return false, err end --- Can be returned in the desired format/order 
end

print(UserOwnsGamePassAsync(665958081,20767517)) 

I noticed that directly trying to read from the contents of Success and Err doesn’t work so I resort to using a separate variable that changes IF success is true.

Ok, I solved my problem, It was my stupid mistake. I forgot “.Value” after many of the variables so it was always reading true even though UserOwnsGamePassAsync was sending false. Thank you everyone for your help