How can I make something where after apon purchasing a Developer Product, a GUI Pops up

I am still getting the same error…


I don’t even know DataModel is

1 Like
local GamepassId = 23359376

script.Parent.MouseButton1Click:Connect(function()

	game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, GamepassId)
	
	local StarterGUI = script.Parent.Parent.Parent.Parent.Parent.Parent
	
	StarterGUI.ThankYouMessage.Visible = true
end
1 Like

Okay so when you click it, it does now show the GUI, but I only want it to show AFTER you purchase it, if you click Cancel I don’t want it to show. Only if they click Purchase

1 Like
local StarterGUI = script.Parent.Parent.Parent.Parent.Parent.Parent


local GamepassId = 23359376

script.Parent.MouseButton1Click:Connect(function()

	game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, GamepassId)
	
wait(1)
	
	StarterGUI.ThankYouMessage.Visible = true
end
1 Like

Again, I said I only want it to show if they purchase, that will show it no matter what…

1 Like

So do you know how I can achieve my problem?

1 Like
local StarterGUI = script.Parent.Parent.Parent.Parent.Parent.Parent
local GamepassId = 23359376
local localPlayer = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    game:GetService("MarketplaceService"):PromptGamePassPurchase(localPlayer, GamepassId)

    local player, id, wasPurchased
    repeat
        player, id, wasPurchased = game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Wait()
    until player == localPlayer and id == GamepassId

    if wasPurchased then
        StarterGUI.ThankYouMessage.Visible = true
    end
end)
5 Likes

Yes. Right now I’m trying to figure out how to write the script.

1 Like

Wow, this actually worked! Thank you so much! It’s very appreciated!

2 Likes

Alright so @rubitonlive actually got a working script, and I honestly do appreciate your help! Thank you! Have a nice rest of your day, and again I really do appreciate your effort, and willing to help me, I know I am hard to work with :joy:

3 Likes

Hey, quick question! How can I get it to work on the Developer Product?

local MPS = game:GetService("MarketplaceService")
local id = 1212048436
local plr = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	
	MPS:PromptProductPurchase(plr, id)
	
end)
1 Like

with developer products, it’s slightly more complicated since you can’t conveniently :Wait() like in the example i did; you could create a callback which triggers a BindableEvent which you wait for.

2 Likes

Is StarterGui the StarterGui folder or a ScreenGui?

2 Likes
local MPService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local StarterGui = script.Parent.Parent.Parent.Parent.Parent.Parent
local ProductId = 23359376 --change to developer product id

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(Player, ProductId)
end)

MPService.PromptProductPurchaseFinished:Connect(function(UserId, ProductId, IsPurchased)
	if IsPurchased then
		StarterGui.ThankYouMessage.Visible = true
	end
end)
2 Likes
local MPService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local StarterGUI = script.Parent.Parent.Parent.Parent.Parent.Parent
local GamepassId = 23359376

script.Parent.MouseButton1Click:Connect(function()
	MPService:PromptGamePassPurchase(Player, GamepassId)
end)

MPService.PromptGamePassPurchaseFinished:Connect(function(Player, GamepassId, WasPurchased)
	if WasPurchased then
		StarterGUI.ThankYouMessage.Visible = true
	end
end)

Decided to clean the other one up too (the loop isn’t necessary).

3 Likes

Hey! How can I make it so a GUI Closes if they press cancel?

1 Like

Please do not use PromptProductPurchaseFinished for developer product receipts as it has been deprecated. Instead use ProcessReceipt callback. Follow the API closely to avoid data loss / duplicating handler functions.

1 Like

Even if I have a script that gives you the currency that you buy once upon purchasing the developer product, that isn’t inside that script? This is the script that gives the currency.

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
	
	if receiptInfo.ProductId == 1212048436 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		wait(3.25)
		plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 1450000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
	if receiptInfo.ProductId == 1212045793 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		wait(3.25)
		plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 750000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
	if receiptInfo.ProductId == 1212047578 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		wait(3.25)
		plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 125000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
	if receiptInfo.ProductId == 1212046005 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		wait(3.25)
		plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 60000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
	if receiptInfo.ProductId == 1212046063 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		wait(3.25)
		plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 10000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
end
1 Like

I see you got the Gui closes if not purchased working. I’m going to slightly edit the ProcessReceipt function for you.

1 Like
local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1212048436 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if plr then
			plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 1450000
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end

	elseif receiptInfo.ProductId == 1212045793 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if plr then
			plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 750000
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
	elseif receiptInfo.ProductId == 1212047578 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if plr then
			plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 125000
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
	elseif receiptInfo.ProductId == 1212046005 then
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if plr then
			plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value + 60000
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end
1 Like