Can't find out if the player has a gamepass

So in short, I created a gamepass, customized it and copied the ID, then wrote a local script when the player will buy a gamepass:

wait(0.3)

local vipId = 227863941
local button = script.Parent.Parent.DonateGui.gamepasses.VipPass

local player = game:GetService("Players").LocalPlayer
local mps = game:GetService("MarketplaceService")

local function buyVip()
	mps:PromptGamePassPurchase(player, vipId)
end

button.MouseButton1Click:Connect(buyVip)
button.TouchTap:Connect(buyVip)

but for some reason, when I press the button, it says this:

I decided to check if the player really has a gamepass, so I wrote this server script:

local mps = game:GetService("MarketplaceService")
local vipId = 227863941

game.Players.PlayerAdded:Connect(function(player)
	if mps:PlayerOwnsAsset(player, 227863941) then
		print("player has a pass")
	else
		print("player hasn't a pass")
	end
end)

and this is what I got

I admit that I may have written something wrong somewhere because this is my first attempt to work with gamepasses.

P.S. In the end, I want to achieve the following. I have a player in the game who receives cups, I want that without gamepass he gets for example 1 cup, and with gamepass in 2 times more. I would also like that when you leave the game gamepass saved

You need to run the UserOwnsGamePassAsync function instead of PlayerOwnsAsset.

1 Like

Well, I tried to do what you said, but I got this error:

local mps = game:GetService("MarketplaceService")
local vipId = 227863941

game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player, 227863941) then -- here
		print("player has a pass")
	else
		print("player hasn't a pass")
	end
end)

That’s because the first argument when using :UserOwnsGamePassAsync() should be the playerId and not the player Instance. Change player with player.UserId.

1 Like

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