Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does this script not trigger when Dev Product was purchased?

Asked by
DogeIXX 172
4 years ago

Hey, I am trying to make a script which processes a Developer product. Now, the purchasing works, but the script does not trigger. I don't get errors either.

local market = game:GetService("MarketplaceService")
local Https = game:GetService("HttpService")
local function processreceipt(receiptInfo)
    print("received it")
        local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        local id = receiptInfo.ProductId
        if not plr then
            return Enum.ProductPurchaseDecision.NotProcessedYet
        else

        print("Purchased!"
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

market.ProcessReceipt = processreceipt

It does not print "received it".

0
You can only set one ProcessReceipt. Any other assignment will override the current function User#5423 17 — 4y
0
Okay, but I only have this one function in the game. Do I understand something wrong? DogeIXX 172 — 4y
0
why does https exist? RobloxGameingStudios 145 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Here's some code from the official Roblox page that I edited to work, change the ID to whatever dev purchase happens and change what it does below the 'then'. You can add more of them if needed I haven't tested it yet.

local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")
local function getPlayerByUserId(userId)
    for _, player in pairs(Players:GetPlayers()) do
        if player.UserId == userId then
            return player
        end
    end
end

local function processReceipt(receiptInfo)

    -- Find the player who made the purchase in the server
    local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        -- The player probably left the game
        -- If they come back, the callback will be called again
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Output what product they bought
    if receiptInfo.ProductId == 940739628 then
        player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
    else
        print("do nothing")
    end
    print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)

    -- IMPORTANT: Tell Roblox that the game successfully handled the purchase
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

-- Set the callback (this can only be done once by one script on the server!)
MarketplaceService.ProcessReceipt = processReceipt

Please accept if this solves your problem. If you have any questions please feel free to ask in the comments.

0
pls accept Oh yea and this goes in ServerScriptService as a normal script. RobloxGameingStudios 145 — 4y
Ad

Answer this question