So, I am trying to make it so when you click a button, it checks if you have the gamepass, and if you do then it runs some code. and if you don't have the gamepass, it prompts you to buy it. my problem is that when you accept the prompt and you buy the gamepass, it does not change my assigned variable to run the rest of the code. Is there a fix for this?

Here's my full code. it's in a localscript.

local btn = script.Parent
local fr = btn.Parent.Parent.changeLicenseKey
local win = btn.Parent.Parent

local mps = game:GetService("MarketplaceService")

local gamePassId = 25727086
local hasPass = false

local function promptPurchase()
	local plr = game.Players.LocalPlayer
	hasPass = false
	
	local success, message = pcall(function()
		hasPass = mps:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, gamePassId)
	end)
	if not success then
		warn(message)
	end
	
	if plr then
		if hasPass == true then
			print("Player already owns gamepass "..gamePassId)
			print(gamePassId.." gamepass is owned by "..game.Players.LocalPlayer.Name)
			win.top.appName.Text = win.top.appName.Text.." - Choose A License Key"
			fr.Visible = true
			btn.Parent.Visible = false
		else
			mps:PromptGamePassPurchase(plr, gamePassId)
			print("Gamepass not owned")
		end
	end
end

btn.Activated:Connect(function()
	promptPurchase()
end)

mps.PromptGamePassPurchaseFinished:Connect(function(plr, id, successBuy)
	if successBuy and id == gamePassId then
		hasPass = true
		print("hasPass = true")
	end
end)

Thanks!

1 comment

0

Be more descriptive in your question. What methods did you try? Did you use print statements for debugging? etc. The more descriptive an answer is the more likely it is to be answered by the community!