Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Working purchase, but no change on the Leaderboard?

Hello, I am having problem with Developer Product - the purchase pop-up does work and completed, but the problem I am having that the Leaderboard is not changing it's value.

Another words: The purchase thing works - just that the Leaderboard doesn't update the Coins after purchase.

Can anyone help me with the scripting???

Here is the part of the script that doesn't work.

mps.ProcessReceipt = function(info)
local plr = tonumber(getPlayerById(info.PlayerId))
if plr and plr:FindFirstChild "leaderstats" and plr.leaderstats:FindFirstChild "Coins" then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 5
end
end

Here is a full script.

local buyButton = script.Parent
local productId = 19187415
local mps = game:GetService"MarketplaceService"

function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end

buyButton.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

mps.ProcessReceipt = function(info)
local plr = tonumber(getPlayerById(info.PlayerId))
if plr and plr:FindFirstChild "leaderstats" and plr.leaderstats:FindFirstChild "Coins" then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 5
end
end

3 comments

0

You should check to make sure the productId's match, and if they do THEN award the stats. Also your "plr" is just the Player'sID not the actual player.

0

You also need to use Enum.ProductPurchaseDecision.PurchaseGranted

2 answers

developer products are very annoying, i got'it fixed after around 15 tries, here's the script ;)

local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = DEVELOPER PRODUCT ID HERE

 
MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
 

if receiptInfo.ProductId == ProductID then

--Do stuff here

            end
        end	
    end


    return Enum.ProductPurchaseDecision.PurchaseGranted		
end

2 comments

0

I will try this script, if it works - I will mark it as an answer!

0

I doesn't work!

What about this? I tried the script above, but it doesn't work! Does this part of the script that needs changing?

Script Line:

buyButton.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

mps.ProcessReceipt = function(info)
local plr = tonumber(getPlayerById(info.PlayerId))
if plr and plr:FindFirstChild "leaderstats" and plr.leaderstats:FindFirstChild "Coins" then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 5
end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.