PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

PromptPurchase

PromptPurchase is used to prompt a player to purchase an item with the given assetId. Below is a screenshot of the purchase dialogue that appears when this function is called.

The purchase dialogue triggered by PromptPurchase

The above dialogue was triggered using the following:

game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, 4367427794)

For game passes, use MarketplaceService/PromptGamePassPurchase.

Parameters

Name Type Default Description
true
Default

Ignored.

Returns

Return Type Summary

Code Samples


LocalScript (Client)

The below example would prompt all new players to buy Beautiful Hair for Beautiful People when they click on a part.

Place this LocalScript somewhere on the Client such as within Players -> StarterPlayerScripts so that it will be able to fire a RemoteEvent/FireServer signal from a Client to the Server.

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent") -- Wait until the RemoteEvent exists, since it is being created by the Server

-- Create a part on the client that triggers our promptPurchaseEvent clicked
local part = Instance.new("Part")
part.Parent = game.Workspace

local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part

-- When the ClickDetector is clicked by the player, fire an event to the Server
clickDetector.MouseClick:Connect(function()
	promptPurchaseEvent:FireServer(16630147) -- Pass in an ID
end)

Script (Server)

Since the below code is listening for a RemoteEvent/OnServerEvent to fire to the Server from a Client. Place this script somewhere on the Server such as within ServerScriptStorage.

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

-- Setup RemoteEvent in ReplicatedStorage
local promptPurchaseEvent = Instance.new("RemoteEvent")
promptPurchaseEvent.Name = "PromptPurchaseEvent"
promptPurchaseEvent.Parent = ReplicatedStorage
 
-- Listen for the RemoteEvent to fire from a Client and then trigger the purchase prompt
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
	MarketplaceService:PromptPurchase(player, id)
end)