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

What's wrong with my DeveloperProducts script?

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

✓ Accepted answer

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.

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