開發者產品

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

一個 開發者產品 是一個使用者可以購買多次的物品或能力,例如遊戲內貨幣、彈藥或藥水。

創建開發者產品

要創建開發者產品:

  1. 前往 創作 並選擇一個遊戲。
  2. 前往 貨幣化開發者產品
  3. 點擊 創建開發者產品
  4. 上傳一個圖像作為產品圖標。確保圖像不超過 512x512 像素,重要細節不在其圓形邊界之外,並且為 .jpg.png.bmp 格式。
  5. 為產品輸入名稱和描述。
  6. 選擇產品的類別。類別用於組織你遊戲內商店中的物品。
  7. 設定產品價格為 Robux。最低價格為 1 Robux,最高價格為 10 億 Robux。
  8. 點擊 保存變更

獲取開發者產品 ID

要使用腳本,你需要一個開發者產品 ID。要獲取產品 ID:

  1. 前往 貨幣化開發者產品

  2. 懸停在某個產品的縮略圖上,點擊 按鈕,並從上下文菜單中選擇 複製資產 ID

銷售開發者產品

在銷售開發者產品之前,請確保你正確處理銷售收據並授予用戶他們購買的產品。為此,你必須:

  • 使用 ProcessReceipt API 來檢查購買收據。ProcessReceipt 會自動讀取並確認用戶在遊戲外購買了產品。
  • 驗證每個收據的 User IDDeveloper Product ID 和收據狀態。
  • 如果收據的狀態為 開放,則授予用戶他們購買的開發者產品。
  • ProcessReceipt API 的回應中包含一條確認收據的消息,並驗證所購買的物品已被授予。

你可以以兩種方式銷售開發者產品:

在你的遊戲內

要在遊戲內實現並銷售開發者產品,請調用 MarketplaceService 函數。

使用 GetProductInfo 獲取關於開發者產品的信息,如名稱和價格,然後將該產品顯示給用戶。例如,你可以在遊戲的市場中銷售產品。對於開發者產品,第二個參數必須是 Enum.InfoType.Product


local MarketplaceService = game:GetService("MarketplaceService")
-- 將占位符 ID 替換為你的開發者產品 ID
local productId = 000000
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
end)
if success and productInfo then
-- 顯示產品信息
-- 將打印語句替換為顯示產品的 UI 代碼
print("開發者產品名稱: " .. productInfo.Name)
print("價格 (Robux): " .. productInfo.PriceInRobux)
print("描述: " .. productInfo.Description)
end

使用 GetDeveloperProductsAsync 獲取與你的遊戲相關的所有開發者產品。此函數返回一個 Pages 物件,你可以檢查並過濾以構建遊戲內商店或產品列表 GUI。


local MarketplaceService = game:GetService("MarketplaceService")
local success, developerProducts = pcall(function()
return MarketplaceService:GetDeveloperProductsAsync()
end)
if success and developerProducts then
local firstPage = developerProducts:GetCurrentPage()
for _, developerProduct in firstPage do
-- 將打印語句替換為顯示產品的 UI 代碼
print(field .. ": " .. value)
end
end

使用 PromptProductPurchase 來提示遊戲內的產品購買。當用戶執行按鈕按下或與 NPC 交談等操作時,可以調用此函數。


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 將占位符 ID 替換為你的開發者產品 ID
local productId = 000000
local function promptProductPurchase()
local success, errorMessage = pcall(function()
MarketplaceService:PromptProductPurchase(player, productId)
end)
if success then
print("成功顯示購買提示")
end
end

你也可以將函數組合在 LocalScript 中。例如,你可以創建一個 UI 元素,如按鈕或 NPC,然後使用 GetProductInfo() 將現有的開發者產品與該元素連接,檢查產品是否在售,並使用 PromptProductPurchase() 在用戶點擊時提示購買。


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
-- 將占位符 ID 替換為你的開發者產品 ID
local productId = 000000
-- 當用戶點擊 UI 按鈕時獲取產品信息
button.MouseButton1Click:Connect(function()
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
end)
if success and productInfo then
-- 檢查產品是否在售
if productInfo.IsForSale then
print("這個產品在售")
-- 提示產品購買
MarketplaceService:PromptProductPurchase(player, productId)
else
-- 通知產品不在售
print("該產品目前不在售。")
end
else
print("獲取產品信息時出錯: " .. tostring(productInfo))
end
end)

在你的遊戲外

要啟用游戲外的開發者產品購買,你必須使用 ProcessReceipt API。在用戶在你遊戲的 商店 標籤中進行購買後,必須使用 ProcessReceipt 確認其購買,並在用戶進入你的遊戲後授予他們的物品。

測試模式

測試模式 功能有助於你通過在遊戲外模擬開發者產品購買來驗證你的購買流程。在啟用外部開發者產品銷售之前,應使用測試模式確保你已正確實現 ProcessReceipt

在測試模式下你放上架銷售的開發者產品僅能被你和你的組織成員看到。對用戶是不可見的。

要測試你的實現:

  1. 創作者中心 中,前往 貨幣化開發者產品
  2. 點擊 菜單,選擇 外部購買設置
  3. 外部購買設置 頁面中,點擊 啟用測試模式
  4. 測試模式啟用後,返回 開發者產品 頁面並選擇一個產品進行測試。
  5. 基本設置 頁面中,選擇 允許外部購買 复選框並保存更改。
  6. 前往遊戲詳情頁的 商店 標籤,購買你已上線銷售的產品。
  7. 進入遊戲並確認你已收到所購買的產品。 ProcessReceipt API 的收據狀態應更新為 已關閉

在測試完成後,Roblox 會驗證測試是否成功並允許你完全啟用外部銷售開發者產品的功能。

有關 ProcessReceipt API 及其實現的更多信息,請參見 ProcessReceipt 頁面。

啟用外部銷售

要啟用外部銷售:

  1. 前往 外部購買設置 頁面。
  2. 打開 外部購買
  3. 返回 開發者產品 頁面,選擇你想在遊戲外銷售的產品。
  4. 基本設置 頁面中,選擇 允許外部購買 复選框並保存更改。
  5. 確認這些產品現在可以在遊戲詳細頁的 商店 標籤中購買。

要禁用開發者產品的外部銷售,請在 開發者產品 頁面上選擇該產品並清除 允許外部購買 复選框。

限制

  • 測試模式中的商品銷售實際需要Robux。我們建議測試低成本的開發者產品。
  • 測試模式中的商品僅可被你或你小組的成員看到。
  • 要在外部銷售,你的開發者產品 必須 具有縮略圖。
  • 不應在遊戲外銷售以下項目:
    • 付費隨機物品
    • 數量、時間、地點或使用者設置和角色有限制的物品

處理開發者產品購買

在用戶購買開發者產品後,必須處理並記錄該交易。為此,請使用 ScriptServerScriptService 中使用 ProcessReceipt 函數。

有關 ProcessReceipt API 及其實現的更多信息,請參見 ProcessReceipt 頁面。


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
-- 例:產品 ID 123123 使用戶恢復全滿健康
productFunctions[123123] = function(receipt, player)
local character = player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = humanoid.MaxHealth
-- 表示成功購買
return true
end
end
-- 例:產品 ID 456456 向用戶發放 100 個金幣
productFunctions[456456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local gold = leaderstats and leaderstats:FindFirstChild("Gold")
if gold then
gold.Value += 100
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- 獲取與開發者產品 ID 相關的處理函數並嘗試運行它
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- 用戶已收到其物品
-- 返回 "PurchaseGranted" 確認交易
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("處理收據失敗:", receiptInfo, result)
end
end
-- 無法授予用戶的物品
-- 返回 "NotProcessedYet" 並在下次用戶加入遊戲時再次嘗試
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- 設置回調
-- 這只能由一個伺服器端腳本做一次
MarketplaceService.ProcessReceipt = processReceipt

個性化你的遊戲內商店

你可以使用產品智能 APIs 來對開發者產品進行排序並向用戶推薦。個性化你的遊戲內商店有助於顯示出對每個用戶最相關的物品,提升參與度和收入。通過根據用戶偏好定制開發者產品,你可以提高其發現的機會,增加轉換率,並開啟新的貨幣化機會。

排名可售的開發者產品

RankProductsAsync 接受一個產品 ID 的列表並返回這些產品的個性化排序列表。你可以使用此方法為用戶提供個性化的物品推薦,並在你的遊戲內商店中顯示。

範例:為用戶排名的三個 "力量" 物品
為用戶排名的三個物品。

local MarketplaceService = game:GetService("MarketplaceService")
-- 創建一個你想排名的產品數組
local productIdentifiers = {
{InfoType = Enum.InfoType.GamePass, Id = 123},
{InfoType = Enum.InfoType.Product, Id = 456},
{InfoType = Enum.InfoType.Product, Id = 789}
}
-- 進行保護性調用以處理錯誤
local success, rankedProducts = pcall(function()
return MarketplaceService:RankProductsAsync(productIdentifiers)
end)
if not success then
error("排名產品失敗")
end
-- 將返回的項目加載到商店中
for i, rankedItem in ipairs(rankedProducts) do
local productIdentifier = rankedItem.ProductIdentifier
local productInfo = rankedItem.ProductInfo
-- ...
-- 邏輯以將產品添加到商店
end

顯示你的頂級開發者產品

RecommendTopProductsAsync 接受一個 InfoType 值的數組並返回用戶最有可能參與和購買的最多 50 個項目。你可以使用此方法在遊戲內商店中創建一個 "精選" 區域。

如果無法確定任何推薦,RecommendTopProductsAsync 將返回 0 個項目。

在少數情況下,對排名模型的調用可能會較慢。為了避免給用戶帶來延遲,我們建議使用 task.spawn 使調用 RecommendTopProducts 非阻塞。

範例:遊戲內商店中的 "精選" 標籤
遊戲內商店的精選標籤。

local MarketplaceService = game:GetService("MarketplaceService")
-- 創建一個你想包含在推薦中的產品類型數組 -- 本範例包含通行證和開發者產品
local productTypes = {Enum.InfoType.GamePass, Enum.InfoType.Product}
-- 進行保護性調用以處理錯誤
local success, topRankedItems = pcall(function()
return MarketplaceService:RecommendTopProductsAsync(productTypes)
end)
if not success then
error("排名產品失敗")
end
-- 將返回的項目加載到商店中
-- 確保過濾掉 topRankedItems 中的任何不合格物品,例如用戶不再能夠購買的開發者產品
for i, rankedItem in ipairs(topRankedItems) do
local productIdentifier = rankedItem.ProductIdentifier
local productInfo = rankedItem.ProductInfo
-- ...
-- 邏輯以將產品添加到商店
end

開發者產品分析

使用開發者產品分析來分析單個產品的成功,識別趨勢並預測潛在的未來收入。

通過分析,你可以:

  • 查看在選定時間內你最高的開發者產品。
  • 通過時間序列圖展示最多八個銷售最高的項目,以分析總體銷售和淨收入。
  • 監控你的目錄並按銷售和淨收入對物品進行排序。

要訪問開發者產品分析:

  1. 前往 創作 並選擇一個遊戲。
  2. 前往 貨幣化開發者產品
  3. 選擇 分析 標籤。
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。