I'm trying to make a ROBLOX lottery and I need to know when the player buys an asset (Developer product) and It doesn't print anything. FE is on and it's in a serverscript in Workspace. The problem is no output, except for the purchase prompt. Here's the code.
local productId = 31191997 game.Players.PlayerAdded:connect(function(player) game:GetService("MarketplaceService").PromptPurchaseFinished:connect(function(player, assetId, isPurchased) if isPurchased then print(player.Name .. " bought an item with AssetID: " .. assetId) else print(player.Name .. " didn't buy an item with AssetID: " .. assetId) end end) game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end)
You should record this using ProcessReceipt. Use my Example below:
local MarketplaceService = game:GetService("MarketplaceService") local ID = 31191997 local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId if PurchaseHistory:GetAsync(playerProductKey) then return Enum.ProductPurchaseDecision.PurchaseGranted end for i, player in ipairs(game.Players:GetPlayers()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == ID then print("Player has purchased a developer product!") end end end PurchaseHistory:SetAsync(playerProductKey, true) return Enum.ProductPurchaseDecision.PurchaseGranted end
In the coding above, it recorded the transaction of the developer product if it was bought, if it didn't, nothing happend. Hope this helped! If it did, please Accept me as an answer and we both get reputation!