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

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

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

1 comment

0

Save it

1 answer

✓ Accepted answer

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


3 comments

0

I think he means globally

0

Yeah i mean Globally. Like for the whole game in general how to make a limited amount of something

0

Have a separate data store to store the amount of it then you should be set

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