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
)GetDeveloperProductsAsync
Dönüşler
Kod Örnekleri
PazarYeriServisi:GeliştiriciÜrünleriniAlAsync
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
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)İşlem Toptan Satın Alma Sunucusu
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local promptBulkPurchaseEvent = Instance.new("RemoteEvent")
promptBulkPurchaseEvent.Name = "PromptBulkPurchaseEvent"
promptBulkPurchaseEvent.Parent = ReplicatedStorage
--Bir İstemciden RemoteEvent'in ateşlenmesini bekleyin ve ardından toplu satın alma istemini 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:Ürün Satın Alma İsteği
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local productId = 0000000 -- Bunu geliştirici ürün kimliğinize değiştirin
-- Geliştirici ürününün satın alım isteği fonksiyonu
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şlemesi için RemoteEvent'i dinleyin ve sonra 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ığı
endOlaylar
PromptBulkPurchaseFinished
MarketplaceService.PromptBulkPurchaseFinished(
Parametreler
PromptBundlePurchaseFinished
PromptGamePassPurchaseFinished
MarketplaceService.PromptGamePassPurchaseFinished(
Kod Örnekleri
Oyun Geçişi Satışı Tamamlandı
local MarketplaceService = game:GetService("MarketplaceService")
local function gamepassPurchaseFinished(...)
-- İsteğin tüm ayrıntıları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
Fatura İşleme Callback
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- İşlemleri 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 bir satın alımı vermek için işleyici fonksiyonunu sorgulamak için bir sözlük
-- Bu fonksiyonlar, satın alma başarılı bir şekilde verilirse true döner
-- Bu fonksiyonlar asla yield etmemelidir çünkü daha sonra UpdateAsync() callback içinde çağrılacaklardır
local grantPurchaseHandlerByProductId = {
[productIdByName.fullHeal] = function(_receipt, player)
local character = player.Character
local humanoid = character and character:FindFirstChild("Humanoid")
-- Oyuncunun iyileştirilmesi için bir humanoidi olduğundan emin olun
if not humanoid then
return false
end
-- Oyuncuyu tam sağlığa iyileştirin
humanoid.Health = humanoid.MaxHealth
-- Başarılı bir verme durumunu belirtin
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 ekleyin
goldStat.Value += 100
-- Başarılı bir verme durumunu belirtin
return true
end,
}
-- Temel ProcessReceipt callback fonksiyonu
-- Bu uygulama çoğu hata senaryosunu işler ancak sunucular arası veri hata 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 verildi olarak kaydedildi, bu yüzden daha önce ele alınmış olmalı
-- Satın alımı iki kez vermemek için burada verme işleyicisini çağırmaktan kaçının
-- Veri deposundaki değer zaten true iken, pcall sonuç değişkeninin de true olması için tekrar true döner
-- Bu daha sonra fatura 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 yoksa satın alımı vermeyi önler
-- Yeniden katıldıklarında, bu fatura 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 alma işlenemez
-- Bu, deneyimde satılan her ürün kimliği için bir işleyici ayarlandığı sürece asla gerçekleşmeyecektir
warn(`Ürün kimliği '{receiptInfo.ProductId}' için tanımlı bir satın alma işleyici yok`)
return nil
end
local handlerSucceeded, handlerResult = pcall(grantPurchaseHandler, receiptInfo, player)
if not handlerSucceeded then
local errorMessage = handlerResult
warn(
`'{player.Name}' kullanıcısından '{receiptInfo.ProductId}' ürün kimliğiyle yapılan satın alımı işlerken Grant satın alma işleyicisi hata verdi: {errorMessage}`
)
return nil
end
local didHandlerGrantPurchase = handlerResult == true
if not didHandlerGrantPurchase then
-- İşleyici satın alımı vermedi, bu yüzden kayıttan verilmedi olarak kaydedin
return nil
end
-- Satın alım şimdi oyuncuya verilmiştir, bu yüzden kaydedin olarak verildi
-- Bu daha sonra fatura 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 fatura 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
-- Callback'i ayarlayın; bu yalnızca sunucudaki bir script tarafından bir kez yapılabilir
MarketplaceService.ProcessReceipt = processReceipt