luarobloxmarketplace

How to perfectly make developer products in roblox?


I have been learning to make roblox games, but recently I got an issue where the code is correct but the thing doesn't work.
I am doing as per this roblox website.

But even when i do the similar kind of thing it doesn't work. Can anyone correct me where I'm going wrong?


local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local donateEvent = ReplicatedStorage:WaitForChild("donateEvent")

local ProductFunctions = {}

ProductFunctions[1249752191] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752535] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752534] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752537] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752533] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752530] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752532] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752536] = function(Player)
    donateEvent:FireClient(Player)
end
ProductFunctions[1249752531] = function(Player)
    donateEvent:FireClient(Player)
end

MarketPlaceService.ProcessReceipt = function(info)
    local Player = Players:GetPlayerByUserId(info.PlayerId)
    local Product = info.PurchaseId

    if not Player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    local success, err = pcall(ProductFunctions[Product],Player)
    if not success then
        warn('error')
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

My problem here is that even though the process receipt is there and the ID exactly matches with the given values to be checked. The event inside the function doesn't fire at all! Not even 1 event is fired in all of them...


Solution

  • Well the problem was that i wrote

    local Product = info.PurchaseId
    

    It should actually be

    local Product = info.ProductId