Motor Sınıfı
MarketplaceService
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Özet
Yöntemler
Olaylar
PromptBulkPurchaseFinished(player: Instance,status: Enum.MarketplaceBulkPurchasePromptStatus,results: Dictionary):RBXScriptSignal |
PromptBundlePurchaseFinished(player: Instance,bundleId: number,wasPurchased: boolean):RBXScriptSignal |
PromptGamePassPurchaseFinished(player: Instance,gamePassId: number,wasPurchased: boolean):RBXScriptSignal |
PromptProductPurchaseFinished(userId: number,productId: number,isPurchased: boolean):RBXScriptSignal |
PromptPurchaseFinished(player: Instance,assetId: number,isPurchased: boolean):RBXScriptSignal |
PromptRobloxSubscriptionPurchaseFinished(user: Player,didTryPurchasing: boolean):RBXScriptSignal |
PromptSubscriptionPurchaseFinished(user: Player,subscriptionId: string,didTryPurchasing: boolean):RBXScriptSignal |
Geri Aramalar
ProcessReceipt(receiptInfo: Dictionary):Enum.ProductPurchaseDecision |
API Referansı
Yöntemler
BindReceiptHandler
MarketplaceService:BindReceiptHandler(
Parametreler
Dönüşler
Kod Örnekleri
MarketplaceService:BindReceiptHandler
-- NOT: Eğer işleyiciniz sürekli avantajlar (para birimi, öğeler) sağlıyorsa, kullanın
-- DataStoreService:UpdateAsync() TransferRequestId üzerinde, aynı makbuzun
-- birden fazla sunucuya teslim edilmesi durumunda çift verilmesi önlemek için.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
-- Gönderen makbuzlarıyla ilgilen (Robux gönderen oyuncu)
MarketplaceService:BindReceiptHandler(
Enum.ReceiptType.RobuxTransferSender,
function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- Oyuncu bu sunucuda değil; makbuzun
-- şu anda bulunduğu sunucuya yeniden teslim edilmesi için ertele
return Enum.ReceiptDecision.NotProcessedYet
end
print(
`{player.Name} {receiptInfo.CurrencySpent} Robux gönderdi`
.. ` (TransferRequestId: {receiptInfo.TransferRequestId})`
)
-- Gönderen tarafında herhangi bir onay verme veya UI'yi güncelleme burada gerçekleşir
return Enum.ReceiptDecision.Processed
end
)
-- Alıcı makbuzlarıyla ilgilen (Robux alan oyuncu)
MarketplaceService:BindReceiptHandler(
Enum.ReceiptType.RobuxTransferReceiver,
function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ReceiptDecision.NotProcessedYet
end
print(
`{player.Name} {receiptInfo.CurrencySpent} Robux aldı`
.. ` (TransferRequestId: {receiptInfo.TransferRequestId})`
)
-- Alıcı tarafında herhangi bir yarar sağlama veya UI'yi güncelleme burada gerçekleşir
return Enum.ReceiptDecision.Processed
end
)MarketplaceService:BindReceiptHandler
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- 100 jeton veren geliştirici ürün ID'si ile değiştirin
local COINS_PRODUCT_ID = 123456789
local COINS_PER_PURCHASE = 100
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
-- Bir filtre dizisi geçmek, bu işleyiciyi yalnızca listelenen ürün ID'lerine bağlar.
-- Filtreyi atlayarak, filtrelenmiş bir işleyici tarafından talep edilmeyen herhangi bir
-- geliştirici ürün makbuzu için tetiklenen bir genel işleyici kaydedebilirsiniz.
MarketplaceService:BindReceiptHandler(
Enum.ReceiptType.DeveloperProduct,
function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- Alıcı bu sunucuda değil; makbuzun
-- daha sonra veya bir sonraki sunucuya katıldıklarında yeniden teslim edilmesi için erteleyin
return Enum.ReceiptDecision.NotProcessedYet
end
-- Ürünü tam olarak bir kez verin, aynı makbuz
-- birden fazla kez teslim edilse bile, PurchaseId'ye göre anahtar alarak. Geri çağırma
-- yalnızca fayda kalıcı olarak verildiğinde doğru olarak kaydedilir, bu nedenle
-- UpdateAsync, bu makbuz tamamlandığında tam olarak doğru olarak çözülür.
local success, granted = pcall(function()
return purchaseHistoryStore:UpdateAsync(receiptInfo.PurchaseId, function(alreadyGranted)
if alreadyGranted then
-- Önceki bir teslimat bu satın alımı zaten verdi; tekrar
-- vermeyin, ancak makbuzu çözülmüş olarak tutun
return true
end
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if not coins then
-- Oyuncunun istatistikleri henüz hazır değil. Yazmayı iptal etmek için nil döndürün
-- böylece hiçbir şey verilmiş olarak kaydedilmez ve
-- makbuz daha sonra yeniden teslim edilir
return nil
end
coins.Value += COINS_PER_PURCHASE
return true
end)
end)
if not success or granted ~= true then
-- Bir veri deposu hatası oluştu veya fayda verilmedi; bırakın
-- makbuz çözülmemiş kalsın, böylece daha sonra yeniden teslim edilir
return Enum.ReceiptDecision.NotProcessedYet
end
return Enum.ReceiptDecision.Processed
end,
{ COINS_PRODUCT_ID }
)GetDeveloperProductsAsync
Dönüşler
Kod Örnekleri
MarketplaceService:GetDeveloperProductsAsync
local MarketplaceService = game:GetService("MarketplaceService")
local developerProducts = MarketplaceService:GetDeveloperProductsAsync():GetCurrentPage()
for _, developerProduct in pairs(developerProducts) do
for field, value in pairs(developerProduct) do
print(field .. ": " .. value)
end
print(" ")
endGetProductInfo
GetProductInfoAsync
Parametreler
| Varsayılan değer: "Asset" |
Dönüşler
Kod Örnekleri
Ürün Bilgisi Alma
local MarketplaceService = game:GetService("MarketplaceService")
local ASSET_ID = 125378389
local asset = MarketplaceService:GetProductInfoAsync(ASSET_ID)
print(asset.Name .. " :: " .. asset.Description)Fiyat İndirimlerini Gösterme
local MarketplaceService = game:GetService("MarketplaceService")
local PASS_ID = 12345678
local textLabel = script.Parent
local DiscountTypeDisplay = {
RobloxPlusSubscription = "Roblox Plus İndirimi",
}
local productInfo = MarketplaceService:GetProductInfoAsync(PASS_ID, Enum.InfoType.GamePass)
print(string.format("Orijinal Fiyat: %d", productInfo.UserBasePriceInRobux))
for _, discount in ipairs(productInfo.PriceDiscountDetails) do
local displayName = DiscountTypeDisplay[discount.Type] or "Diğer İndirim"
print(string.format("%s (%d%%): -%d", displayName, discount.Percent, discount.AmountInRobux))
end
print(string.format("Ödemeniz Gereken: %d", productInfo.PriceInRobux))Mevcut Zamanlı Seçenekleri Gösterme
local MarketplaceService = game:GetService("MarketplaceService")
local info = MarketplaceService:GetProductInfoAsync(105589844216517, Enum.InfoType.Asset)
if info.TimedOptions then
for _, option in info.TimedOptions do
local days = option.Duration / 86400
print(string.format("%d gün - %d Robux", days, option.Price))
end
endŞeffaf Gruplama ile Paralel GetProductInfoAsync
local MarketplaceService = game:GetService("MarketplaceService")
local productIds = {123456, 987654, 555777}
local results = {}
local remaining = #productIds
local function fetch(productId)
local success, info = pcall(function()
return MarketplaceService:GetProductInfoAsync(productId, Enum.InfoType.Product)
end)
if success then
results[productId] = info
else
warn("Ürün bilgisi alınamadı:", productId, info)
end
remaining -= 1
end
-- Tüm çağrıları eşzamanlı olarak başlatmak, motorun bunları
-- otomatik olarak daha az HTTP isteğine gruplamasını sağlar.
for _, productId in productIds do
task.spawn(fetch, productId)
end
-- Tüm isteklerin tamamlanmasını bekleyin.
while remaining > 0 do
task.wait()
end
-- Tüm sonuçlar artık mevcut.
for productId, info in results do
print(info.Name, "-", info.PriceInRobux, "Robux")
endGetRobloxSubscriptionDetailsAsync
Parametreler
Dönüşler
Kod Örnekleri
Roblox Abonelik Detaylarını Kontrol Et
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local success, details = pcall(function()
return MarketplaceService:GetRobloxSubscriptionDetailsAsync(player)
end)
if success and details.IsSubscribed then
-- 1. Bağlılığı Kontrol Et (örn., > 60 gün abone)
local threeMonths = 60 * 24 * 60 * 60
if details.StartTime and (os.time() - details.StartTime.UnixTimestamp) > threeMonths then
print("'3-Aylık Abonelik Veteranı' kıyafetini veriyor!")
end
-- 2. Atımı Kontrol Et
if details.IsOriginExperience then
print("Atım onaylandı: Kullanıcı bu deneyim üzerinden abone oldu.")
else
print("Kullanıcı başka bir yerde (Web sitesi veya başka bir Deneyim) abone oldu.")
end
end
end)GetSubscriptionProductInfoAsync
Parametreler
Dönüşler
GetUsersPriceLevelsAsync
Parametreler
Dönüşler
{PriceLevelInfo}
Kod Örnekleri
Bir kullanıcılar listesi için fiyat seviyelerini al
-- MarketplaceService'i al
local MarketplaceService = game:GetService("MarketplaceService")
-- Bir liste kullanıcı için fiyat seviyelerini almak için bir işlev tanımlayın
local function getPriceLevels(userIds)
local success, result = pcall(function()
return MarketplaceService:GetUsersPriceLevelsAsync(userIds)
end)
if success then
-- Her PriceLevelInfo'yu bir UserId -> PriceLevel karşılık gelen tabloya eşleyin
local lookup = {}
for _, info in ipairs(result) do
lookup[info.UserId] = info.PriceLevel
end
return lookup
else
warn("Fiyat seviyeleri alınırken hata:", result)
return nil
end
end
-- Yer tutucu ID'ler kullanarak örnek
local user1Id = 123456789
local user2Id = 987654321
-- İşlevi çağırın ve sonucu saklayın
local priceLevels = getPriceLevels({user1Id, user2Id})
-- Başarılıysa, her kullanıcının seviyesini yazdırın
if priceLevels then
print("Kullanıcı 1'in fiyat seviyesi:", priceLevels[user1Id])
print("Kullanıcı 2'nin fiyat seviyesi:", priceLevels[user2Id])
else
print("Fiyat seviyelerini alma başarısız oldu.")
endGetUserSubscriptionDetailsAsync
Dönüşler
GetUserSubscriptionPaymentHistoryAsync
Dönüşler
Kod Örnekleri
MarketplaceService:GetUserSubscriptionPaymentHistoryAsync
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local SUBSCRIPTION_ID = "EXP-0"
local function checkSubscriptionHistory(player: Player)
local subscriptionHistory = {}
local success, err = pcall(function()
subscriptionHistory = MarketplaceService:GetUserSubscriptionPaymentHistoryAsync(player, SUBSCRIPTION_ID)
end)
if not success then
warn(`Abonelik geçmişini kontrol ederken hata: {err}`)
return
end
if next(subscriptionHistory) then
-- Kullanıcının son 12 ay içinde bazı abonelik geçmişi var.
-- Abonelik geçmişindeki her ödeme girişinin ayrıntılarını yazdır.
print(`Oyuncu {player.Name} daha önce {SUBSCRIPTION_ID} aboneliğine sahipti:`)
for entryNum, paymentEntry in subscriptionHistory do
local paymentStatus = tostring(paymentEntry.PaymentStatus)
local cycleStartTime = paymentEntry.CycleStartTime:FormatLocalTime("LLL", "en-us")
local cycleEndTime = paymentEntry.CycleEndTime:FormatLocalTime("LLL", "en-us")
print(`{entryNum}: {paymentStatus} ({cycleStartTime} - {cycleEndTime})`)
end
else
print(`Oyuncu {player.Name} daha önce {SUBSCRIPTION_ID} aboneliğine sahip olmamıştır.`)
end
end
-- Oyundaki mevcut tüm oyuncular için checkSubscriptionHistory çağrısı yap
for _, player in ipairs(Players:GetPlayers()) do
checkSubscriptionHistory(player)
end
-- Gelecek tüm oyuncular için checkSubscriptionHistory çağrısı yap
Players.PlayerAdded:Connect(checkSubscriptionHistory)GetUserSubscriptionStatusAsync
Dönüşler
Kod Örnekleri
Kullanıcı Abonelik Durumunu Kontrol Et
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local subscriptionID = "EXP-00000"
local function checkSubStatus(player)
local subStatus = {}
local success, message = pcall(function()
-- IsRenewing ve IsSubscribed değerlerini döndürür
subStatus = MarketplaceService:GetUserSubscriptionStatusAsync(player, subscriptionID)
end)
if not success then
warn("Abonelik durumu kontrol edilirken hata: " .. tostring(message))
return
end
if subStatus["IsSubscribed"] then
print(player.Name .. " abone oldu: " .. subscriptionID)
-- Abonelikle ilişkili izinleri verin
end
end
Players.PlayerAdded:Connect(checkSubStatus)PlayerOwnsAsset
PlayerOwnsAssetAsync
Dönüşler
Kod Örnekleri
Öğe Mülkünü Kontrol Et
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
-- Kontrol ettiğimiz öğe: https://www.roblox.com/catalog/30331986/Midnight-Shades
local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"
local function onPlayerAdded(player)
local success, doesPlayerOwnAsset =
pcall(MarketplaceService.PlayerOwnsAssetAsync, MarketplaceService, player, ASSET_ID)
if not success then
local errorMessage = doesPlayerOwnAsset
warn(`{player.Name} {ASSET_NAME} öğesine sahip olup olmadığını kontrol ederken hata: {errorMessage}`)
return
end
if doesPlayerOwnAsset then
print(`{player.Name} {ASSET_NAME} öğesine sahip`)
else
print(`{player.Name} {ASSET_NAME} öğesine sahip değil`)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)PlayerOwnsBundle
PlayerOwnsBundleAsync
Dönüşler
Kod Örnekleri
Paket Sahipliğini Kontrol Et
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
-- Kontrol ettiğimiz paket: https://www.roblox.com/bundles/589/Junkbot
local BUNDLE_ID = 589
local BUNDLE_NAME = "Junkbot"
Players.PlayerAdded:Connect(function(player)
local success, doesPlayerOwnBundle = pcall(function()
return MarketplaceService:PlayerOwnsBundleAsync(player, BUNDLE_ID)
end)
if success == false then
print("PlayerOwnsBundleAsync çağrısı başarısız oldu: ", doesPlayerOwnBundle)
return
end
if doesPlayerOwnBundle then
print(player.Name .. " sahip " .. BUNDLE_NAME)
else
print(player.Name .. " sahip değil " .. BUNDLE_NAME)
end
end)PromptBulkPurchase
Parametreler
Dönüşler
()
Kod Örnekleri
Toplu Satın Alma İstemcisi
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promptBulkPurchaseEvent = ReplicatedStorage:WaitForChild("PromptBulkPurchaseEvent")
local part = Instance.new("Part")
part.Parent = workspace
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
clickDetector.MouseClick:Connect(function()
promptBulkPurchaseEvent:FireServer({
{ Type = Enum.MarketplaceProductType.AvatarAsset, Id = "16630147" },
{ Type = Enum.MarketplaceProductType.AvatarBundle, Id = "182" },
})
end)Toplu Satın Alma İsteği Sunucusu
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local promptBulkPurchaseEvent = Instance.new("RemoteEvent")
promptBulkPurchaseEvent.Name = "PromptBulkPurchaseEvent"
promptBulkPurchaseEvent.Parent = ReplicatedStorage
-- İstemciden ateşlenen RemoteEvent'i dinleyin ve ardından toplu satın alma isteğini tetikleyin
promptBulkPurchaseEvent.OnServerEvent:Connect(function(player, items)
MarketplaceService:PromptBulkPurchase(player, items, {})
end)Zaman Sınırlı Seçenek Satın Alma İstemi
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ASSET_ID = 105589844216517
Players.PlayerAdded:Connect(function(player)
local info = MarketplaceService:GetProductInfoAsync(ASSET_ID, Enum.InfoType.Asset)
if info.TimedOptions and #info.TimedOptions > 0 then
-- En kısa süreli seçeneği bul
local shortest = info.TimedOptions[1]
for _, option in info.TimedOptions do
if option.Duration < shortest.Duration then
shortest = option
end
end
local items = {
{
Type = Enum.MarketplaceProductType.AvatarAsset,
Id = tostring(ASSET_ID),
PurchaseOptions = {
{ Type = Enum.PurchaseOption.TimedOption, Value = shortest.Duration },
},
}
}
MarketplaceService:PromptBulkPurchase(player, items, {})
end
end)PromptBundlePurchase
PromptCancelSubscription
PromptGamePassPurchase
PromptPremiumPurchase
PromptProductPurchase
MarketplaceService:PromptProductPurchase(
):()
Parametreler
| Varsayılan değer: true |
| Varsayılan değer: "Default" |
Dönüşler
()
Kod Örnekleri
MarketplaceService:PromptProductPurchase
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local productId = 0000000 -- Bunu geliştirici ürün ID'niz ile değiştirin
-- Geliştirici ürününün satın alınmasını istemek için fonksiyon
local function promptPurchase()
MarketplaceService:PromptProductPurchase(player, productId)
end
promptPurchase()PromptPurchase
MarketplaceService:PromptPurchase(
):()
Parametreler
| Varsayılan değer: true |
| Varsayılan değer: "Default" |
Dönüşler
()
Kod Örnekleri
YerelScript (İstemci)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent")
local part = Instance.new("Part")
part.Parent = workspace
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
clickDetector.MouseClick:Connect(function()
promptPurchaseEvent:FireServer(16630147)
end)Script (Sunucu)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local promptPurchaseEvent = Instance.new("RemoteEvent")
promptPurchaseEvent.Name = "PromptPurchaseEvent"
promptPurchaseEvent.Parent = ReplicatedStorage
-- İstemciden ateşlenen RemoteEvent'i dinleyin ve ardından satın alma istemini tetikleyin
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
MarketplaceService:PromptPurchase(player, id)
end)PromptRobloxSubscriptionPurchase
Parametreler
Dönüşler
()
Kod Örnekleri
Roblox Plus Abonelik Satın Alma İsteği
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local teleporter = script.Parent
local showModal = true
local EXCLUSIVE_AREA_POSITION = Vector3.new(1200, 200, 60)
-- Abonelik ücretini ödeyen oyuncuya ödülü ver ve özel alana ışınla
local function grantRewardAndTeleport(player)
player:RequestStreamAroundAsync(EXCLUSIVE_AREA_POSITION)
local character = player.Character
if character and character.Parent then
local currentPivot = character:GetPivot()
character:PivotTo(currentPivot * CFrame.new(EXCLUSIVE_AREA_POSITION))
end
end
-- Karakter parçalarının teleporter'a dokunmasını tespit et
teleporter.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if not player then
return
end
if not player:GetAttribute("CharacterPartsTouching") then
player:SetAttribute("CharacterPartsTouching", 0)
end
player:SetAttribute("CharacterPartsTouching", player:GetAttribute("CharacterPartsTouching") + 1)
if player.HasRobloxSubscription then
-- Oyuncunun zaten Roblox Plus aboneliği var; ödülü hemen ver
grantRewardAndTeleport(player)
else
-- Roblox Plus abonelik isteği, birkaç saniyede bir gösterilecek şekilde sönümlendi
if not showModal then
return
end
showModal = false
task.delay(5, function()
showModal = true
end)
MarketplaceService:PromptRobloxSubscriptionPurchase(player)
end
end)
-- Teleporter'dan çıkan karakter parçalarını tespit et
teleporter.TouchEnded:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player and player:GetAttribute("CharacterPartsTouching") then
player:SetAttribute("CharacterPartsTouching", player:GetAttribute("CharacterPartsTouching") - 1)
end
end)
-- Sunucu bir abonelik değişikliğini onayladığında ödül ver
-- Her oyuncu için HasRobloxSubscription değişikliğini bağla
Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("HasRobloxSubscription"):Connect(function()
if player.HasRobloxSubscription
and player:GetAttribute("CharacterPartsTouching")
and player:GetAttribute("CharacterPartsTouching") > 0
then
grantRewardAndTeleport(player)
end
end)
end)PromptRobuxTransferAsync
Dönüşler
Kod Örnekleri
MarketplaceService:PromptRobuxTransferAsync
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
-- Örnek: Bir oyuncu bir RemoteEvent tetiklediğinde Robux transferi yapma
local transferEvent = game.ReplicatedStorage:WaitForChild("RequestTransfer")
transferEvent.OnServerEvent:Connect(function(sender, receiverUserId, amount)
-- Girdileri doğrula
if not sender or not sender:IsA("Player") then
return
end
if typeof(receiverUserId) ~= "number" or receiverUserId <= 0 then
warn("Geçersiz receiverUserId")
return
end
if typeof(amount) ~= "number" or amount <= 0 then
warn("Geçersiz miktar")
return
end
local success, result = pcall(function()
return MarketplaceService:PromptRobuxTransferAsync(sender, receiverUserId, amount)
end)
if success then
print(`Transfer başlatıldı, TransferRequestId: {result}`)
else
warn(`Transfer başarısız oldu: {result}`)
end
end)PromptSubscriptionPurchase
RankProductsAsync
Parametreler
Dönüşler
{RankedItem}
Kod Örnekleri
Verilen ürün kimliklerine dayalı olarak sıralı ürünlerin bir listesini alın
-- MarketplaceService'i alın
local MarketplaceService = game:GetService("MarketplaceService")
-- Sıralamak istediğiniz ürünlerin dizisini oluşturun
local productIdentifiers = {
{InfoType = Enum.InfoType.GamePass, Id = 123},
{InfoType = Enum.InfoType.Product, Id = 456},
{InfoType = Enum.InfoType.Product, Id = 789}
}
-- Hataları zarif bir şekilde ele almak için korumalı bir çağrı yapın
local success, rankedProducts = pcall(function()
return MarketplaceService:RankProductsAsync(productIdentifiers)
end)
if not success then
error("Ürünleri sıralama başarısız oldu")
end
-- Döndürülen öğeleri mağazaya yükleyin.
for i, rankedItem in ipairs(rankedProducts) do
local productIdentifier = rankedItem.ProductIdentifier
local productInfo = rankedItem.ProductInfo
-- ...
-- Ürünleri mağazaya eklemek için mantık
endRecommendTopProductsAsync
Parametreler
Dönüşler
{RankedItem}
Kod Örnekleri
Deneyim içi mağazanızda en iyi ürünlerin sıralı listesini alın
-- MarketplaceService'i al
local MarketplaceService = game:GetService("MarketplaceService")
-- Dahil edilecek ürün türleri için bir dizi oluştur. Bu durumda hem oyun geçişleri hem de geliştirici ürünleri
local productTypes = {Enum.InfoType.GamePass, Enum.InfoType.Product}
-- Hataları zarif bir şekilde ele almak için korumalı bir çağrıda bulunun
local success, topRankedItems = pcall(function()
return MarketplaceService:RecommendTopProductsAsync(productTypes)
end)
if not success then
error("Ürünleri sıralamakta başarısız")
end
-- Döndürülen öğeleri mağazaya yükleyin. Kullanıcının artık satın alamayacağı geliştirici ürünleri gibi, topRankedItems'dan uygun olmayan öğeleri filtrelediğinizden emin olun
for i, rankedItem in ipairs(topRankedItems) do
local productIdentifier = rankedItem.ProductIdentifier
local productInfo = rankedItem.ProductInfo
-- ...
-- Ürünleri mağazaya ekleme mantığı
endUserOwnsGamePassAsync
Dönüşler
Kod Örnekleri
Şeffaf Gruplama ile Birden Fazla Oyun Geçişini Kontrol Etme
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PASS_IDS = {1234567, 2345678, 3456789, 4567890}
local function checkPassesForPlayer(player: Player)
local owned = {}
local remaining = #PASS_IDS
local function check(passId)
local success, ownsPass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId)
end)
if success and ownsPass then
table.insert(owned, passId)
end
remaining -= 1
end
-- Tüm çağrıları eşzamanlı olarak başlatmak, motorun bunları
-- otomatik olarak daha az HTTP isteğine gruplamasını sağlar.
for _, passId in PASS_IDS do
task.spawn(check, passId)
end
while remaining > 0 do
task.wait()
end
return owned
end
Players.PlayerAdded:Connect(function(player)
local ownedPasses = checkPassesForPlayer(player)
print(player.Name, "sahip", #ownedPasses, "geçiş")
end)Olaylar
PromptBulkPurchaseFinished
MarketplaceService.PromptBulkPurchaseFinished(
Parametreler
PromptBundlePurchaseFinished
PromptGamePassPurchaseFinished
MarketplaceService.PromptGamePassPurchaseFinished(
Kod Örnekleri
Oyun Geçişi Satın Alma Tamamlandı
local MarketplaceService = game:GetService("MarketplaceService")
local function gamepassPurchaseFinished(...)
-- İsteğin tüm detaylarını yazdır, örneğin:
-- PromptGamePassPurchaseFinished PlayerName 123456 false
print("PromptGamePassPurchaseFinished", ...)
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)PromptProductPurchaseFinished
PromptPurchaseFinished
MarketplaceService.PromptPurchaseFinished(
Kod Örnekleri
PromptPurchaseFinished Olayını Yönetme
local MarketplaceService = game:GetService("MarketplaceService")
local function onPromptPurchaseFinished(player, assetId, isPurchased)
if isPurchased then
print(player.Name, "bir öğeyi AssetID ile satın aldı:", assetId)
else
print(player.Name, "AssetID ile bir öğe satın almadı:", assetId)
end
end
MarketplaceService.PromptPurchaseFinished:Connect(onPromptPurchaseFinished)PromptRobloxSubscriptionPurchaseFinished
MarketplaceService.PromptRobloxSubscriptionPurchaseFinished(
Kod Örnekleri
Handle PromptRobloxSubscriptionPurchaseFinished Olayını
local MarketplaceService = game:GetService("MarketplaceService")
local function onPromptRobloxSubscriptionPurchaseFinished(player, didTryPurchasing)
if didTryPurchasing then
-- Oyuncu abonelik için deneme yaptı; onaylamak için HasRobloxSubscription değişikliğini bekleyin
print(player.Name, "Roblox Plus abone olmayı denedi")
else
print(player.Name, "Roblox Plus abonelik istemini satın almadan kapattı")
end
end
MarketplaceService.PromptRobloxSubscriptionPurchaseFinished:Connect(onPromptRobloxSubscriptionPurchaseFinished)Geri Aramalar
ProcessReceipt
Parametreler
Dönüşler
Kod Örnekleri
İşlem Makbuzu Geri Çağırma
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- Başarılı bir şekilde işlenen satın alımları takip etmek için veri deposu ayarı
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local productIdByName = {
fullHeal = 123123,
gold100 = 456456,
}
-- Bir ürün kimliğine karşılık gelen satın alımı vermek için işleyici fonksiyonu aramak için bir sözlük
-- Bu fonksiyonlar, satın alımın başarıyla verilip verilmediğini kontrol eder
-- Bu fonksiyonlar, UpdateAsync() geri çağırması içinde daha sonra çağrıldıkları için asla beklememelidir
local grantPurchaseHandlerByProductId = {
[productIdByName.fullHeal] = function(_receipt, player)
local character = player.Character
local humanoid = character and character:FindFirstChild("Humanoid")
-- Oyuncunun iyileşmesi için bir humanoid olduğundan emin olun
if not humanoid then
return false
end
-- Oyuncuyu tam Sağlık ile iyileştir
humanoid.Health = humanoid.MaxHealth
-- Başarılı bir verişi belirt
return true
end,
[productIdByName.gold100] = function(_receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local goldStat = leaderstats and leaderstats:FindFirstChild("Gold")
if not goldStat then
return false
end
-- Oyuncunun altın istatistiğine 100 altın ekle
goldStat.Value += 100
-- Başarılı bir verişi belirt
return true
end,
}
-- Temel İşlem Makbuzu geri çağırma fonksiyonu
-- Bu uygulama çoğu hata senaryosunu ele alır ancak sunucular arası veri hatası senaryolarını tamamen hafifletmez
local function processReceipt(receiptInfo)
local success, result = pcall(
purchaseHistoryStore.UpdateAsync,
purchaseHistoryStore,
receiptInfo.PurchaseId,
function(isPurchased)
if isPurchased then
-- Bu satın alım zaten verilmiş olarak kaydedildi, bu nedenle daha önce işlenmiş olmalıdır
-- Satın alımı iki kez vermemek için burada veriş işleyicisini çağırmaktan kaçının
-- Veri deposundaki değer zaten doğru olsa da, pcall sonuç değişkeninin de doğru olması için tekrar doğru döner
-- Bu daha sonra makbuz işlemcisinden PurchaseGranted döndürmek için kullanılacaktır
return true
end
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- Oyuncu sunucuda değilse satın alımı vermekten kaçınır
-- Yeniden katıldıklarında, bu makbuz işlemcisi tekrar çağrılacaktır
return nil
end
local grantPurchaseHandler = grantPurchaseHandlerByProductId[receiptInfo.ProductId]
if not grantPurchaseHandler then
-- Bu ürün kimliği için tanımlı bir işleyici yoksa, satın alım işlenemez
-- Bu, deneyimde satılan her ürün kimliği için bir işleyici ayarlandığı sürece asla olmayacaktır
warn(`Ürün kimliği '{receiptInfo.ProductId}' için tanımlı bir satın alım işleyici yok`)
return nil
end
local handlerSucceeded, handlerResult = pcall(grantPurchaseHandler, receiptInfo, player)
if not handlerSucceeded then
local errorMessage = handlerResult
warn(
`'{player.Name}' tarafından '{receiptInfo.ProductId}' ürün kimliğine ait satın alım işlenirken veriş işleyici hatası: {errorMessage}`
)
return nil
end
local didHandlerGrantPurchase = handlerResult == true
if not didHandlerGrantPurchase then
-- İşleyici satın alımı vermedi, bu nedenle kaydedin olarak verilmedi
return nil
end
-- Satın alım artık oyuncuya verilmiştir, bu nedenle kaydedin olarak verilmiştir
-- Bu daha sonra makbuz işlemcisinden PurchaseGranted döndürmek için kullanılacaktır
return true
end
)
if not success then
local errorMessage = result
warn(`Veri deposu hatası nedeniyle makbuzu işleme başarısız oldu: {errorMessage}`)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local didGrantPurchase = result == true
return if didGrantPurchase
then Enum.ProductPurchaseDecision.PurchaseGranted
else Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Geri çağırmayı ayarlayın; bu yalnızca sunucudaki bir betik tarafından bir kez yapılabilir
MarketplaceService.ProcessReceipt = processReceipt