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

What's wrong with my DeveloperProducts script?

Asked by 10 years ago

I am trying to make it so when they click the purchase button, it will add the specified amount, local Amount = player.PlayerGui.CurrencyGui.CashFrame.Amount.Value To there Cash when they purchase it.

This is what I tried.

Amount = Amount+Cash

However I don't know what's wrong with it. Is there a better method to do this?

local cash = script.Parent.Cash.Value
local buyButton = script.Parent
local productId = 0
local player = game.Players.LocalPlayer
local Amount = player.PlayerGui.CurrencyGui.CashFrame.Amount.Value


buyButton.MouseButton1Click:connect(function()

    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
Amount = Amount+Cash


end)

I tried doing the full path instead right here on line 11. Wouldn't that work?

local buyButton = script.Parent
local productId = 0
local player = game.Players.LocalPlayer



buyButton.MouseButton1Click:connect(function()

    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)

player.PlayerGui.CurrencyGui.CashFrame.Amount.Value = player.PlayerGui.CurrencyGui.CashFrame.Amount.Value + script.Parent.Cash.Value

end)

1 answer

Log in to vote
2
Answered by 10 years ago

Have the purchase button have the following;

local buyButton = script.Parent
local productId = 0
local player = game.Players.LocalPlayer
buyButton.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

And now have a script in ServerScriptService to control the purchases:

local productId1 = 0
local data = Game:GetService("DataStoreService"):GetDataStore("Purchases")
Game:GetService("MarketplaceService").ProcessReceipt = function(info)
    for i,v in pairs(Game.Players:GetPlayers:GetPlayers()) do
        if v.userId == info.PlayerId and not data:GetAsync(tostring(info.PurchaseId)) then
            if productId1 == info.ProductId then
                v.PlayerGui.CurrencyGui.CashFrame.Amount.Value = v.PlayerGui.CurrencyGui.CashFrame.Amount.Value + v.PlayerGui.Gui.Cash.Value -- Change to path of player's cash value.
                data:SetAsync(tostring(info.PurchaseId), "Purchased")
                return Enum.ProductPurchaseDecision.PurchaseGranted     
            end
        end
    end
    return Enum.ProductPurchaseDecision.NotProcessedYet
end

The ProcessReceipt callback is used for handling developer product purchases. You can find more information here.

Ad

Answer this question