MarkeplaceService:UserOwnsGamePassAsync Returns false even when the gamepass is purchased

  1. I want to understand why UserOwnsGamePassAsync doesn’t work and returns the opposite value.

  2. I have made test-purchase in studio and I get the item but then when I equip it, it get’s destroyed because the tool thinks I do not have the gamepass even though I do.

  3. I have tried to search for solutions on the forum but methods didn’t fix my issue.

So this is the code for the tool that can only be used if the player has the gamepass. Any help is greatly appreciated!

local Tool = script.Parent
local Player = Tool.Parent.Parent
local Humanoid = Player.Character.Humanoid
local Pass = 123123 -- For demo purposes
local MarketplaceService = game:GetService("MarketplaceService")

Tool.Equipped:Connect(function()
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Pass) then
		Humanoid.WalkSpeed += 14
	else
		Tool:Destroy()
	end
end)

Tool.Unequipped:Connect(function()
	Humanoid.WalkSpeed -= 14
end)
1 Like

It looks like you don’t have the correct GamePass ID
You have it set to 123123, I imagine that isn’t the correct ID.

local Pass = 123123 -- // Change this to the correct ID
1 Like

It is written right next that it’s for demonstration purposes. I have the real correct ID when I tested it. The problem is on the MarketplaceService:UserOwnsGamePassAsync.

1 Like

In the code snippet provided you have it set to 123123, It’s not EVER going to return true if you don’t make it the correct ID

1 Like

The code snippet is for clarity. The script I am using in studio has the “correct” ID. All works just when it comes to checking if the player has it.


This may explain the reason. I only need a way to work around and make it working.

1 Like

You could set an attribute to the player when the gamepass is bought, and instead of checking with the MarketPlaceService:UserOwnsGamePassAsync() use an attribute. Here is an example that you could try using.

local Tool = script.Parent
local Player = Tool.Parent.Parent
local Humanoid = Player.Character.Humanoid
local Pass = 123123 -- For demo purposes
local MarketplaceService = game:GetService("MarketplaceService")

local GamepassAttributeName = "HasToolGamepass" --/// Change it to any name you like, should be a boolean attribute

Tool.Equipped:Connect(function()
	if Player:GetAttribute(GamepassAttributeName) == true then
		Humanoid.WalkSpeed += 14
	else
		Tool:Destroy()
	end
end)

Tool.Unequipped:Connect(function()
	Humanoid.WalkSpeed -= 14
end)

Now, all you have to do is add this attribute in two cases:

  1. When the player joins and has the gamepass

  2. When the player buys the gamepass

  3. If you already have a script that checks when a player join, add the UserOwnsGamePassAsync check into it, and add the attribute if it returns true. It could look like this

local Pass = 123123 -- /// Change this to the actual gamepass id
local GamepassAttributeName = "HasToolGamepass" --/// Change it to any name you like, should be a boolean attribute

game.Players.PlayerAdded:Connect(function(Player: Player)
     if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Pass) == true then
         Player:SetAttribute(GamepassAttributeName, true)
     end
end)
  1. When a player buys the gamepass, you should detect it by using the marketplace method " PromptGamePassPurchaseFinished"
local Pass = 123123 -- /// Change this to the actual gamepass id
local GamepassAttributeName = "HasToolGamepass" --/// Change it to any name you like, should be a boolean attribute

local function onGamepassPurchaseFinished(Player: Player, GamepassID: number, WasPurchased: boolean)

   if GamepassID == Pass and WasPurchased == true then
      Player:SetAttribute(GamepassAttributeName, true)
   end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onGamepassPurchaseFinished)

Hope this helps!
If you want to read more, here is the method for purchase finished

Edit: Forgot to add something on the last snippet, should be fixed now

3 Likes

Is there a possible chance that you got it from the link, like here for example. If so it’s probably not the correct ID, as shown from this post UserOwnsGamepassAsync() always returns false even tho I own the gamepass - #19 by Maaron85_1

image

1 Like

I got it from the Copy ID button next to the game pass icon.
image

2 Likes

I’ll give this a shot and let you know if it works.

2 Likes

Well it says pass id, not asset id

It works like that.

It works! Thank you very much for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.