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

Why wont my script work? [Not solved]

I have got this for my developer product to add 5000 cash but it wont work please help.

id = 20566241 --dev product id

script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, id)
    local MarketplaceService = Game:GetService("MarketplaceService")
    local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
    MarketplaceService.ProcessReceipt = function(receiptInfo) 
        if game.Players.LocalPlayer.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == id then
                game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.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)

The error is that it wont give me the 5000 cash and I have to reset to buy it again.

1 answer

This needs to be in a local script inside a GUI within your game, not a regular script. I'm not sure if its already in a local script or not but at first glance seems the most likely error

7 comments

0

Oh ok someone told me a regular

0

game.Players.LocalPlayer can only be called from a LocalScript. Thats the tell-tale sign

0

I will come back and say if it works

0

Ok so it said it wouldn't work because roblox is performing matanence why is this?

0

It still wont work any help?

0

If it says ROBLOX is performing maintenance it means that your trying to buy a developer product from another place. Are you sure this developer product id is for the developer product in your place?

0

Yes I mistyped the Dev Id I have it working now thanks!

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