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

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

Asked by 9 years ago

This question already has an answer here:

Why wont this work? Please 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)
0
It's because no one is even looking at the first ones. TheImmuneNoobKiller 0 — 9y

Marked as Duplicate by SanityMan, TheeDeathCaster, M39a9am3R, and adark

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

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.

0
It does not work please help!!! TheImmuneNoobKiller 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)

0
Got this error in output Players.Player1.PlayerGui.Cash.Frame.TextButton.Script:5: attempt to index local 'p' (a nil value) TheImmuneNoobKiller 0 — 9y
0
Because, Mousebutton1Click doesn't return anything in PlayerGui. Try script.Parent.Parent.Parent.Parent.Parent instead. M39a9am3R 3210 — 9y