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

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

Asked by
BashGuy10 384 Moderation Voter
4 years ago
Edited 4 years ago
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)
0
btw it keeps going like n * n + n, by the third buy you have six tools. BashGuy10 384 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
it keep duplicating tools, gonna post the function fire in the question BashGuy10 384 — 4y
Ad

Answer this question