I need help with a developer product

I want to make a dev product that gives the player 100 Clicks.

It gives the player the correct ammount of Clicks, but then it adds 200 at the next purchase.

I tried lots of other things, but haven’t found anything that works.

local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer
local asset = 1156130202
clicks = 100

script.Parent.MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(plr, asset)
	mps.PromptProductPurchaseFinished:Connect(function(plr, asset, purchased)
		if purchased then
			game.ReplicatedStorage.Remotes.CreditClicks:FireServer(clicks)
		else
			
		end
	end)
end)

(This is my first post, sorry if I got anything wrong.)

Whats the Script receiving the remote look like?

game.ReplicatedStorage.Remotes.CreditClicks.OnServerEvent:Connect(function(plr,clicks)
	plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + clicks
end)

So when you buy it once, your cash goes to 100, but you buy it again and your cash becomes 200?

no, it gains 200 the next time.

I think he means, it gives 200 more after

So it becomes 300, is that correct

Yeah, it gains 100, then gains 200, than gains 300.

1 Like

so in increments of 100.
Ok. in the “Else” statements, try adding ‘return’ instead of nothing

robloxapp-20210306-1606161.wmv (536.7 KB)

Each time you click the button, you create a new PromptProductPurchaseFinished listener. So on the next one you would get 300, then 400, then so on. PromptProductPurchaseFinished is deprecated anyway, so you should set MarketplaceService.ProcessReceipt on the server.

So your client code becomes

-- improved some readability/consistency
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local asset = 1156130202

-- Activated is preferred over MouseButton1Click
script.Parent.Activated:Connect(function()
	mps:PromptProductPurchase(player, asset)
end)

Then in a server script you want to set MarketplaceService.ProcessReceipt.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

function MarketplaceService.ProcessReceipt(receipt)
	local player = Players:GetPlayerByUserId(receipt.PlayerId) -- player id is user id

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet -- maybe left or something
	end

	if receipt.ProductId == 1156130202 then
		player.leaderstats.Clicks.Value += 100
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Learn more here

1 Like