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

Why isn't this marketplace service working?

Asked by 10 years ago

I'm working on a PlayerPoints shop, where you can buy player points with Robux. For some reason, the script errors out in game. Can anyone figure out what is wrong? Thanks.

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local points = game:GetService("PointsService")

local twoPoints = 19642067
local fivePoints = 19642318
local tenPoints = 19642331
local fiftyPoints = 19642337
local hundredPoints = 19642339

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == twoPoints then
                points:AwardPoints(player.userId, 2)
            elseif receiptInfo.ProductId == fivePoints then
                points:AwardPoints(player.userId, 5)
            elseif receiptInfo.ProductId == tenPoints then
                points:AwardPoints(player.userId, 10)
            elseif receiptInfo.ProductId == fiftyPoints then
                points:AwardPoints(player.userId, 50)
            elseif receiptInfo.ProductId == hundredPoints then
                points:AwardPoints(player.userId, 100)
            end
        end
    end 

    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

3 answers

Log in to vote
0
Answered by
c0des 207 Moderation Voter
10 years ago

Well, I am working with my own Developer Products right now and here is my script (It works entirely, except that it gives multiple M1911s instead of just one for some reason...)

local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 19635648

MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do

        if player.userId == receiptInfo.PlayerId then

            if receiptInfo.ProductId == productId then
                game.Lighting:FindFirstChild("Obitor"):Clone().Parent = player.Backpack
                game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased an illegal M1911."
        end
    end
end
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  

    return Enum.ProductPurchaseDecision.PurchaseGranted
end
0
Maybe it's because I was using game.Players:GetChildren() instead of game.Players:GetPlayers()? Would that affect it at all? ForeverDev 155 — 10y
0
I am also using GetChildren() and it works fine other than receiving multiple weapons... Here is what I can think of- Do you have a LocalScript inside StarterPack? If so, what does that LocalScript contain? c0des 207 — 10y
0
I have multiple local scripts inside of the StarterGui, which prompt the players to buy the developer products. ForeverDev 155 — 10y
0
In that case, are you prompted to purchase them? c0des 207 — 10y
View all comments (2 more)
0
What do you mean? :P ForeverDev 155 — 10y
0
When you perform whatever action that is required to call PromptProductPurchase, are you prompted to purchase the Dev Product? c0des 207 — 10y
Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Is it possibly because you have it awarding points? That's probably why.

Also, what is the output errors?

Log in to vote
-2
Answered by 10 years ago

local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo) game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId -- ... -- use DataStore to record purchase -- ...
return Enum.ProductPurchaseDecision.PurchaseGranted
end

                                                     or

local MarketplaceService = Game:GetService("MarketplaceService") local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton local productId = 13672652

buyButton.MouseButton1Click:connect(function() MarketplaceService:PromptProductPurchase(player, productId) end)

                                                     or go here:

http://wiki.roblox.com/index.php?title=Special%3ASearch&profile=default&search=MarketPlace+Service&fulltext=Search

Answer this question