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

How to only sell a limited amount of a dev product?

Asked by 4 years ago

I am trying to make a weapon in which cost robux and there is only a limited quanity of them. Like some games have items which cost robux, that are not gamepasses and they have a timer or a certain quanity before the text says "sold out" Do they do this with dev products? Is there a way to make a dev product only sell a limited amount? Dev product script below

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

Gear1 = 919223646 


local l = game:GetService("Lighting") 
local G1 = l["Autohyperlaser"] 


MarketplaceService.ProcessReceipt = function(receiptInfo)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
    local numberBought = ds:IncrementAsync(playerProductKey, 1)
    for i,v in pairs (game.Players:GetChildren()) do
        if v.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == Gear1 then
                local clone = G1:Clone()
                clone.Parent = v.Backpack
                game.Lighting.pass.Value = true

            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

0
Save it BlackOrange3343 2676 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Just set make a variable holding the max amount and once they purchase it and there is more than 0, it takes one off from the max amount and so on, until it reaches 0.

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

Gear1 = 919223646 


local l = game:GetService("Lighting") 
local G1 = l["Autohyperlaser"] 

local MaxAmount = 30 -- Set this to any amount


MarketplaceService.ProcessReceipt = function(receiptInfo)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
    local numberBought = ds:IncrementAsync(playerProductKey, 1)
    for i,v in pairs (game.Players:GetChildren()) do
        if v.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == Gear1 and MaxAmount > 0 then
                MaxAmount  = MaxAmount -1
                local clone = G1:Clone()
                clone.Parent = v.Backpack
                game.Lighting.pass.Value = true
            elseif receiptInfo.ProductId == Gear1 and MaxAmount <= 0 then
                return Enum.ProductPurchaseDecision.NotProcessedYet  
            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end


0
I think he means globally BlackOrange3343 2676 — 4y
0
Yeah i mean Globally. Like for the whole game in general how to make a limited amount of something ChefDevRBLX 90 — 4y
0
Have a separate data store to store the amount of it then you should be set UltraUnitMode 419 — 4y
Ad

Answer this question