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

[Developer Product Scripts]? [closed]

Asked by 9 years ago

This script doesnt work why?

It was supposed to give my players 10k Cash ingame when buyed.

If anyone has the [Speed,Cash Giver, JetPack] And so on developer script please send them! :)

My leaderboard script is called " LinkedLeaderboard "

local buyButton = script.Parent
local productId = 22771222 --change to dev product id
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 = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild"leaderstats" and plr.leaderstats:FindFirstChild"LinkedLeaderboard" then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10000
end
end



 local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId

    ds:IncrementAsync(playerProductKey, 1) 





    return Enum.ProductPurchaseDecision.PurchaseGranted

Closed as Not Constructive by ConnorVIII and evaera

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that you ended the ProcessReceipt function before updating DataStores, and returning PurchaseGranted.

Also, i'm assuming your third condition in the if statement on line 19 is messing other things up. Remove it, i'm almost positive it's unnecessary.

Lastly, this should only be used in a Server Script, so in your PromptPurchase method you're going to have to find another way to access the player.



Line 19, 3rd Condition;

plr.leaderstats:FindFirstChild"LinkedLeaderboard"



local buyButton = script.Parent
local productId = 22771222 --change to dev product id
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() --Access the player
end)

mps.ProcessReceipt = function(info)
    local plr = getPlayerById(info.PlayerId)
    if plr and plr:FindFirstChild("leaderstats") then
        local stat = plr.leaderstats.Cash
        stat.Value = stat.Value + 10000
    end
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1) 
    return Enum.ProductPurchaseDecision.PurchaseGranted
end
Ad