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

Why this devproduct script don't add gold to player?

Asked by 8 years ago

Hello, I have problem with devproducts. When player buy gold it won't add him it.

Here is script:

game.StarterGui.ResetPlayerGuiOnSpawn = false

local MarketplaceService = game:GetService("MarketplaceService")

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

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = getPlayerFromId(playerId)
    local productName 
    if productId == 32364216 then
        productName = "2,000G"
        local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 2000
        end
    elseif productId == 32364229 then
        productName = "5,000G"
        local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 5000
        end
    elseif productId == 32364246 then
        productName = "10,000G"
        local cashmoney = game.leaderstats.Gold:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 10000
        end
        end
    local message = Instance.new("Hint",workspace)
    message.Text = player.Name.." purchased "..productName.."!"
    coroutine.resume(coroutine.create(function()
        wait(2)
        message:destroy()
    end))

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

I think local cashmoney is wrote wrong...

1 answer

Log in to vote
0
Answered by 8 years ago

Aren't leaderstats contained in the player? So you should have this:

local cashmoney = game.Players[player.Name].leaderstats.Gold -- You might be able to just have "player.leaderstats.Gold" too
0
Okay, thank you :) Yeah i thought about it, but i wanted to ask first. DevKarolus1 70 — 8y
Ad

Answer this question