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

Developer Product Script is functioning in other files but not the one I want it to function in?

Asked by 2 years ago
Edited 2 years ago

I'm going to keep it simple. I'm trying to make a developer product where if you click the gui, it prompts the purchase button, and if you purchase it you get cash added to your leaderstat value. I've searched for many tutorials but I haven't gotten the answer to my problem. The code works properly and gives me the cash when I test it in a separate document, but it gives me an error when I add the exact same code into my main game. The error it gives is:

ReceiptId 9f26cbcb90f3a7a9df7cecef4052bae5 already being processed.

Now I will explain everything I have and my code

I have an image button with a **LocalScript **inside of it. Here is the code:

local mps = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local ID = 000 -- This is the developer product ID

script.Parent.MouseButton1Click:Connect(function()
    mps:PromptProductPurchase(player, ID)
end)

I also have a leaderstat serverscript placed in serverscriptservice. The name of the leaderstat is 'Wins' Here is the script:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Cash= Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Value = 0
    Cash.Parent = leaderstats
end)

I have a seperate serverscript that saves the data of this leaderstat. I thought that was the problem and tried disabling it but it still doesn't work.

Lastly I have a serverscript in serverscriptservice that actually gives the player the cash. Here it is:

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 000 then
        local Player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

Please help.

Answer this question