#developer product that gives money sometimes gives the money to the wron person in the server

1 messages · Page 1 of 1 (latest)

lapis grove
#
local ProductToQuantity = {
    [3296774010] = 25000,
    [3296774101] = 100000,
    [3296774225] = 250000,
}

game.Players.PlayerAdded:Connect(function(player)
    local Leaderstats = player:WaitForChild("leaderstats")

    local function processReceipt(receiptInfo)
        local productId = receiptInfo.ProductId
        local quantity = ProductToQuantity[productId]

        if quantity then
            local Leaderstat = Leaderstats:FindFirstChild("Money") 
            Leaderstat.Value = Leaderstat.Value + quantity
        end

        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    game:GetService("MarketplaceService").ProcessReceipt = processReceipt
end)

the prompts are triggered by clicking on a ui button in starter gui locally (already works)

#

i would appreciate help! i have been stuck with this for days

primal bronze
#

the issue is most likely that you are handling the purchases in a player added event. meaning this code is running for every player that joins the game. instead of getting a player through player added, try using a remote event so that only a single player will be processing

lapis grove
#

how do i fix this? i have no clue

#

since it will break whenever i try something

#

and thank you for your reply

tidal knoll
#

MarketplaceService.ProcessReceipt is a callback, not an event. You can only assign one function at a time

#

You need to strip away Players.PlayerAdded, and use the given receipt to determine the player associated with the purchase

#

Review the documentation on what information is available in the receipt for you to do this

lapis grove
# primal bronze the issue is most likely that you are handling the purchases in a player added e...
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ProductToQuantity = {
    [3296774010] = 25000,
    [3296774101] = 100000,
    [3296774225] = 250000,
}

local purchaseEvent = ReplicatedStorage:WaitForChild("PurchaseEvent")

purchaseEvent.OnServerEvent:Connect(function(player, productId)
    if typeof(productId) == "number" then
        MarketplaceService:PromptProductPurchase(player, productId)
    end
end)


local function processReceipt(receiptInfo)
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    local productId = receiptInfo.ProductId
    local quantity = ProductToQuantity[productId]

    if quantity then
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local moneyStat = leaderstats:FindFirstChild("Money")
            if moneyStat then
                moneyStat.Value = moneyStat.Value + quantity
            end
        end
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

i have tried it and it works! do you see any issues that may cause the money to go to the wrong player? thank you so much i have been stuck with this for days

lapis grove
#

nvm its still not working