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.)
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