Issue with gamepass


i finish game pass system but there small issue

when player want to pay the game pass he will pay it

but the player need to leave and join (to the game pass work)

the script

local gamepass ="IntValue")
	gamepass.Parent = lod
	gamepass.Name = "x2coins"
	gamepass.Value = 1

	if markplaceserver:UserOwnsGamePassAsync(player.UserId,coins2xid) then
		gamepass.Value = 2

thank you for reading

1 Like

From the looks of it, it seems as if you are checking if the player has the gamepass once and then never again. What I recommend you do is that you set up a listener to update the value if the player buys the gamepass. You can do that by utilizing the PromptGamePassPurchaseFinished event.

If you plan on checking on the client, then use the UserOwnsGamePassAsync like you did here, but make sure you call it each time you want to check.

If you want more information on gamepasses, I highly recommend you check out the Game Passes article on the Roblox Creator Documentation. You can find it here.

1 Like

when i search about "PromptGamePassPurchaseFinished" i dont find any thing help me in my issue with game pass

why (bc i dont know where should for me to type ā€œPromptGamePassPurchaseFinishedā€)

i have this script

local mps = game:GetService("MarketplaceService")

local id = 97272435

local player = game.Players.LocalPlayer




with this script

if markplaceserver:UserOwnsGamePassAsync(player.UserId,coins2xid) then
		gamepass.Value = 2

and only i need some help to know

where should for me to type ā€œPromptGamePassPurchaseFinishedā€ function

iā€™m newbie in game pass scripts for that its hard for me);

I am currently from my phone, so Iā€™m unable to present you with a code example, but the problem is that PromptGamePassPurchaseFinished is an event, not a function. It should be used as such:

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, purchaseSuccessful)
    -- Do stuff here

I highly recommend you look at the code examples on the Creator Documentation if you have any further issues.

local marketPlaceService = game:GetService("MarketPlaceService")

local gamepassID = -- gamepass ID

marketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, purchaseSuccess)
     if purchaseSuccess == true and purchasePassID == gamepassID then
        print(player.Name.. " purchased the gamepass")

I went ahead and made an demo that basically achieves what you want. Keep in mind, this is a demo. You should make your code more ā€œsafeā€ by adding more checks, such as in the gamepass function. Hopefully this demo will help you understand:

-- Services --

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Tables --

local GamepassFunctions = {
	[101409980] = function(Player, GamepassId, WasPurchased)
		if WasPurchased then
			print(Player.Name.." purchased gamepass with ID "..GamepassId..". Purchase successful? "..tostring(WasPurchased))
			Player.PlayerInfo.x2Coins.Value = 2

-- Scripting --

	local PlayerInfo ="Folder", Player)
	PlayerInfo.Name = "PlayerInfo"
	local Gamepass ="IntValue", PlayerInfo)
	Gamepass.Name = "x2Coins"
	Gamepass.Value = 1

	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 101409980) then
		Gamepass.Value = 2

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamepassId, WasPurchased)
	if WasPurchased then
		if GamepassFunctions[GamepassId] then
			GamepassFunctions[GamepassId](Player, GamepassId, WasPurchased)

thank you for big help :smiley:

I wish for you good day

1 Like

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