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

In-Game Currency, Developer Products. Please Help?

Asked by
sgsharp 265 Moderation Voter
10 years ago

In my game, I have made a currency called "RoCash." This currency will be used to purchase things in the game.

The Value of "RoCash" is inserted into the player each time they enter the game. A Data Persistence script automatically saves the state of the value each time it has changed. (I am not using DataStore for a reason...)

Okay, I have a Shop GUI, and in the GUI, there's a button that is supposed to add 5 RoCash to the player's RoCash value each time it's purchased...

The Product works just fine. However, adding the RoCash does not. As you can see below, I want the player to receive 5 RoCash. When the product is purchased, it gives the player 20 RoCash... Why? How can I fix this?

Server-Side

local Player = script.Parent.Parent.Parent.Parent.Parent.Parent

local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)

    Player.RoCash.Value = Player.RoCash.Value +5
    wait()
    Player.PlayerGui.Purchases.RoCash.Visible = true
    wait(5)
    Player.PlayerGui.Purchases.RoCash.Visible = false

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

Client-Side

local buyButton = script.Parent
local productId = 19192652
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent

Type = 0

if Player.Name == "Bolohuc" then Type = 2 else Type = 0 end

buyButton.MouseButton1Click:connect(function()
    Game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId, false,  Type)
end)

PLEASE ANSWER AS SOON AS POSSIBLE!

NOTE: I don't want you to change the script unless it's causing the problem... It works fine other than the adding RoCash. Please help me... Provide details with your answer please.

1 answer

Log in to vote
1
Answered by
Gamenew09 180
10 years ago

The ProcessReceipt was called 4 times probably because you tried to buy the developer product before. It should fix itself. I had the exact same problem with Roblox Tower. (EDIT) How did I not notice this! You're trying to get the player using script.Parent.Parent... You need to actually check for the player using the reciptInfo variable. I got this script from the ROBLOX Wiki. EXAMPLE:

local MarketplaceService = game:GetService("MarketplaceService")
local HealthID, GoldID = 11111, 22222
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then -- this is how you get the player.
            -- check which product was purchased (required, otherwise you'll award the wrong items if you're using more than one developer product)
            if receiptInfo.ProductId == HealthID then -- Check developer Product.
                -- handle purchase. In this case we are healing the player.
                player.Character.Humanoid.Health = 100
            elseif receiptInfo.ProductId == GoldID then
                -- handle purchase. In this instance we're giving the player 100 extra gold. 
                player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 100
            end
        end 
    end
    -- record the transaction in a Data Store
    PurchaseHistory:SetAsync(playerProductKey, true)    
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

If I helped vote me up and set this as the answer.

0
I don't understand... It doesn't work when I purchase the product in the game... How can I fix it? sgsharp 265 — 10y
Ad

Answer this question