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

I'm trying to make someone get +5000 cash when they click a button any help?

I have got this but it wont work

id = 20518668 --dev product id

script.Parent.MouseButton1Click: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.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 5000
            end
        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)

2 comments

0

It's because no one is even looking at the first ones.

2 answers

As I have stated in the comment on DeSpizer MouseButton1Click does not return a player in PlayerGui. You turned something that was designed in a free model from SurfaceGui to ScreenGui, so the events and functions don't work the same way.

id = 20518668 --dev product id

script.Parent.MouseButton1Click:connect(function()
p = script.Parent.Parent.Parent.Parent.Parent
    game:GetService("MarketplaceService"):PromptProductPurchase(p.userId, 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.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 5000
            end
        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)

And we do advise against having multiple questions here (though there should be a bump system for after a day, you can bring your question to the front again unless it's locked).


Also, it does help if you explain the situation in detail, if you hadn't posted your error, I would not know how to solve your problem.

1 comment

0

It does not work please help!!!

Try this;

ds = game:service'DataStoreService'
id = 20518668 --dev product id

script.Parent.MouseButton1Click:connect(function(p)
    game:GetService("MarketplaceService"):PromptProductPurchase(p.userId, 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.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 5000
            end
        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)

2 comments

0

Got this error in output Players.Player1.PlayerGui.Cash.Frame.TextButton.Script:5: attempt to index local 'p' (a nil value)

0

Because, Mousebutton1Click doesn't return anything in PlayerGui. Try script.Parent.Parent.Parent.Parent.Parent instead.

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