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

This devproduct script exponentially dupes my tools, anyway to fix it?

local mps = game:GetService("MarketplaceService")

function getPlayerFromId(id)
    for _,v in pairs(game.Players:GetPlayers()) do
        if v.UserId == id then
            return v
        end
    end
end

mps.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = getPlayerFromId(playerId)
    local productName 
    
    if productId == 1004818393 then
        local guns = game.ServerStorage.RandomWeapons:GetChildren()
        local chosenGun = guns[math.random(1, #guns)]:Clone()
        chosenGun = player.Backpack
    end
end

I've never been a good person with devproducts, but now if i give this tool, it exponentially multiplys.

No idea how to fix it TBH.

script.Parent.ClickDetector.MouseClick:Connect(function(clicker)
	local mps = game:GetService("MarketplaceService")
	local player = game.Players:FindFirstChild(clicker.Name)
	mps:PromptProductPurchase(player, 1004818393)
end)

1 comment

0

btw it keeps going like n * n + n, by the third buy you have six tools.

1 answer

Hi there. I don't know much about Dev Products, but on line 20, you wrote chosenGun = player.Backpack. This wouldn't work as you would be setting the choesn gun to player.Backpack. Instead, use .Parent.. Also, there's no need to use an extra function for getting the player from its user ID. You can use the built-in GetPlayerByUserId function of Players.

If this doesn't work, give us the script that fires the receipt function. It might be something simple, like adding a debounce.

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = game.Players:GetPlayerByUserId(playerId)
    local productName 

    if productId == 1004818393 then
        local guns = game.ServerStorage.RandomWeapons:GetChildren()
        local chosenGun = guns[math.random(1, #guns)]:Clone()
        chosenGun.Parent = player.Backpack
    end
end

1 comment

0

it keep duplicating tools, gonna post the function fire in the question

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