What I want to do: The Developer Product purchase screen will appear when the player presses a button is a StarterGui, and if the transaction is successful, I want the player’s display name to be printed on a part on the workspace and a UI to appear.
Codes I have tried before for this:
-- Developer Product ID
local productId = 1234567890
local Model = game.Workspace:WaitForChild("MyModel")
local ScreenGui = game.StarterGui.MyGui
local button = MyGui:WaitForChild("BuyButton")
local textLabel = game.Workspace.MyModel.SurfaceGui.Textlabel
local function onClick()
local success, errorMessage = pcall(function()
game.Players.LocalPlayer:PromptPurchase(productId)
end)
if success then
if textLabel then
textLabel.Text = game.Players.LocalPlayer.Name
end
else
warn("Purchase error:", errorMessage)
end
end
if button then
button.MouseButton1Click:Connect(onClick)
end
As I saw the script, I noticed that some things are missing in this code, which is the MarketplaceService, responsible for using Methods and Events to show prompts and receipts when a Player buys a bundle, asset, gamepass and developer product.
Also, when it comes to showing the GUI, you need to use the PlayerGui as it is a container where it gets a copy from the original GUI created within the class StarterGui.
The script, in a overall perspective, just need some adjustments as it is almost there to work… Here is the new one:
--[Services]--
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
--[Player and Its Containers]--
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
--[Part and Its Elements]--
local TextPart = game.Workspace:WaitForChild("TextPart")
local SurfaceGui = TextPart:WaitForChild("SurfaceGui")
local TextLabel = SurfaceGui:WaitForChild("TextLabel")
--[Developer Product]--
local developerProductId = 1707507094
--[UI and Its Elements]--
local MyGui = PlayerGui:WaitForChild("MyGui")
local TextButton = MyGui:WaitForChild("BuyButton")
--[Function to Show Prompt]--
local function promptPurchaseDeveloperProduct()
MarketplaceService:PromptProductPurchase(Player, developerProductId, false, Enum.CurrencyType.Robux)
end
--[Calling Event]--
TextButton.MouseButton1Click:Connect(function()
promptPurchaseDeveloperProduct()
MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productId, purchaseSuccess)
if purchaseSuccess and productId == developerProductId then
print("Purchase completed")
TextLabel.Text = Player.Name
else
warn("Purchase was not completed")
end
end)
end)
I made it in BillboardGui so you could see that it would print the username. Simply readjusting to SurfaceGui and you are ready to go!
You have to use PromptProductPurchase instead of PromptPurchase
Use MarketplaceService.ProcessReceipt instead of a pcall
You can’t use :PromptPurchase directly on a player instance
This script should hopefully work:
local MarketplaceService = game:GetService("MarketplaceService")
local Player = game:GetService("Players").LocalPlayer
local productId =
local Model = game.Workspace:WaitForChild("MyModel")
local ScreenGui = game.StarterGui.MyGui
local button = MyGui:WaitForChild("BuyButton")
local function ProcessReceiptFunction()
textLabel.Text = Player.Name
end
if button then
button.MouseButton1Click:Connect(function()
MarketplaceService:PromptProductPurchase(Player, productId)
end)
end
MarketplaceService.ProcessReceipt = ProcessReceiptFunction
By the way, you might already know this but the updated text will only change on the client. You should use a serverscript if you want every player to see the updated textlabel.