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

Why is developer product purchase script not working?

Asked by
Seyfert 90
8 years ago
Edited 8 years ago

Okay guys I will try to be quick and organized.

I have one LocalScript in a GUI that consists of this

wait(0.1)
local player = game.Players.LocalPlayer
local currency = player:WaitForChild('leaderstats').Coins
local devid = IDHERE --Give # of coins
Open = false


itembutton.MouseButton1Click:connect(function()
    game:GetService('MarketplaceService'):PromptProductPurchase(game.Players.LocalPlayer, devid)
end)


and then I have another script in ServerScriptService as such

MarketplaceService = game:GetService("MarketplaceService")
local devid = IDHERE


MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i, v in pairs(game.Players:GetChildren()) do    
    if v.userId == receiptInfo.PlayerId then
        if receiptInfo.ProductId == devid then
        v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 100
        local DataStore = game:GetService("DataStoreService")
        local ds1 = DataStore:GetDataStore("coins")
        ds1:SetAsync(v.UserId, v.leaderstats.Coins.Value)   
        wait()
            end
        end     
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

The problem is that I am not getting the plus 100 coins that I should be getting upon buying the devproduct id. The LocalScript works fine, it shows the devproduct and I can purchase it, but then after that I do not get my 100 coins. Why exactly is this? Could you give me any ideas? I have tried resetting the character, still nothing.

1
I'm not seeing the problem, are there any errors with the code? Try printing multiple lines and possibly some variables and information being used by the script to help narrow down your problem. M39a9am3R 3210 — 8y
1
No errors at all which is incredibly strange, I will put a print around each line or so and see what I get Seyfert 90 — 8y
1
Very odd, I just tried it now and it worked. HOWEVER, I exited and joined and bought the devproduct again...and it doesn't work....there seems to be something going on, is it lag? Seyfert 90 — 8y
1
Interesting, when it actually worked, I noticed that the prints from the script were running but when it isn't "working" none of the script's print would appear. Maybe I have too many scritps in the game? I am going to add some waits() to them Seyfert 90 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

I'm sorry I cant give you a good explanation here, however I had the EXACT same problem you did...

I used this link to solve it: ProcessReceipt

If that still doesn't work for you then try this: Handling Multiple Developer Products

Once again I apologise for not being able to explain anything but I hope I've helped in some way.

Ad

Answer this question