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

Devproducts only able to buy one time?

Asked by
Donut792 216 Moderation Voter
5 years ago

so i have my purchase handler script that when a player purchases one of my devproducts they are only able to purchase it once, if they purchase it more than once it will steal their robux and they dont get anything in return

i used to have it without debounce and every if except the first was elseif and that worked fine but every time someone would purchase something it would give them what they paid for plus what they purchase before say they purchase 1000 then purchase 1000 again they get 2000 and if they purchase again they get 3000 and so on and i think nomatter what they purchases it could be 1 million but if they purchased 1000 right before that they would get 2000

so yeah im really struggling here just to get something really simple to work

script:

local Marketplaceservice = game:GetService("MarketplaceService")
local devid = 206197710 --1K
local devid2 = 278740243 --5K
local devid3 = 278740974 --10K
local devid4 = 278742122 --20K
local devid5 = 278742974 --50K
local devid6 = 278743396 --100K
local devid7 = 278760850 --200K
local devid8 = 278761364 --500K
local devid9 = 278761820 --1 Million
local devid10 = 278763424 --Donation
local bought = false
Marketplaceservice.ProcessReceipt = function(receiptinfo)
for i, player in ipairs(game.Players:GetChildren()) do
  if player.UserId == receiptinfo.PlayerId then

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 1000
        bought = false
      end
    end

    if receiptinfo.ProductId == devid2 then
      if not bought then
        bought = true
        player.Nut.Coins.Value = player.Nut.Coins.Value + 5000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid3 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 10000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid4 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 20000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid5 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 50000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid6 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 100000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid7 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 200000
        bought = false
      end
    end

    if not bought then
      bought = true
      if receiptinfo.ProductId == devid8 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 500000
        bought = false
      end
    end

    if not bought then
      bought = false
      if receiptinfo.ProductId == devid9 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 1000000
        bought = false
      end
    end

    if not bought then
      bought = false
      if receiptinfo.ProductId == devid10 then
        player.Nut.Coins.Value = player.Nut.Coins.Value + 4000
        bought = false
      end
    end

  end
end
end
0
You want them to only be able to purchase a devproduct once? Or do you want them to be able to purchase them multiple times? ABK2017 406 — 5y
0
No. Dev products players can buy multiple times, but gamepass they cant, only one time. HaveASip 494 — 5y

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago
Edited 5 years ago

If you want repeated buys(for Devproducts), this is how I have mine set up for comparison. It prompts a product purchase, and loops through players for the receipt, and if the purchase matches the player and devproduct, then awards the value to the leaderstats and ends with the product purchase decision granted. Obviously you would have to modify the devproductId, leaderboard location and stat values. Hopefully it can be a useful example for you.

The local script...

--local script in text button in screengui in startergui

MPS = game:GetService("MarketplaceService")
id = 382513459
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    MPS:PromptProductPurchase(player, id)
end)

The regular script...

--SSS
local MarketplaceService = game:GetService('MarketplaceService')
local devproductId = 382513459 -- The ID of the dev product.

MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == devproductId then

                -- Receive gold
                player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 10000
            end
        end
    end
    return Enum.ProductPurchasedDescision.PurchaseGranted
end
Ad

Answer this question