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

Why is this developer product script not working?

Asked by 10 years ago

Why is this script for my developer product not working?

productId = 20008845


function onClick(Clicker) 
    Player = game.Players:GetPlayerFromCharacter(Clicker.Parent)
    game:GetService("MarketplaceService"):PromptProductPurchase(Player, productId)
end
MS = game:GetService("MarketplaceService")
PH = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MS.ProcessReceipt = function(RI)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.UserId == RI.PlayerId then
            if RI.ProductId == productId then
                player.Character.Health = 0
            end
        end
    end
    playerProductKey = "player_" .. RI.PlayerId .. "_purchased_" .. RI.PurchaseId
    PurchaseHistory.IncrementAsync(playerProductKey, 1)
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

script.Parent.MouseClick:connect(onClick)

Thank you!

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, you didn't have to get the children of players to make this work properly. From looking at the connection line, I see that it's a click detector.

sp = script.Parent
id = 20064983 --dev product id

sp.ClickDetector.MouseClick:connect(function(p)
    game:GetService("MarketplaceService"):PromptProductPurchase(p, id)
    local MarketplaceService = Game:GetService("MarketplaceService")
    local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
    MarketplaceService.ProcessReceipt = function(receiptInfo) 
        if p.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == id then
                p.Character.Humanoid.Health = 0
                -- Alternative to kill them V
                -- p.Character:BreakJoints()
            end

    -- record the transaction in a Data Store
    local playerProductKey = receiptInfo.PlayerId .. "_got_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  

    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

    end
end)

0
it works! Thank you! mariowikiguy 20 — 10y
0
No problem. Shawnyg 4330 — 10y
Ad

Answer this question