#Developer Products buying not working

1 messages · Page 1 of 1 (latest)

cursive nymph
#

So i tried to make Developer Products for the first time, and sometimes when im joining and buying it is working, but sometimes its not working, why?

#

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer

local frame = script.Parent
local buyButton = frame:WaitForChild("BuyButton")

local BuyEvent = ReplicatedStorage:WaitForChild("BuyEvent")

buyButton.MouseButton1Click:Connect(function()
    
    BuyEvent:FireServer(frame.Name)
end)
#

Server Script

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BuyEvent = ReplicatedStorage:FindFirstChild("BuyEvent")
if not BuyEvent then
    BuyEvent = Instance.new("RemoteEvent")
    BuyEvent.Name = "BuyEvent"
    BuyEvent.Parent = ReplicatedStorage
end

local productIDs = {
    ["9 Tokens"] = 3371869616,
    ["49 Tokens"] = 3371870049,
    ["99 Tokens"] = 3371871296,
    ["199 Tokens"] = 3371871718,
    ["499 Tokens"] = 3371872362,
    ["999 Tokens"] = 3371872654
}

local productRewards = {
    [3371869616] = 9,   
    [3371870049] = 49,  
    [3371871296] = 99,  
    [3371871718] = 199,  
    [3371872362] = 499,  
    [3371872654] = 999  
}

BuyEvent.OnServerEvent:Connect(function(player, frameName)
    local productID = productIDs[frameName]
    if productID then
        print(player.Name .. " möchte kaufen: " .. frameName .. " (ID: " .. productID .. ")")
        MarketplaceService:PromptProductPurchase(player, productID)
    else
        warn("Ungültiger Frame: " .. tostring(frameName))
    end
end)
#
local function processReceipt(receiptInfo)
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    local tokens = productRewards[receiptInfo.ProductId]
    if tokens then
        local valueFolder = player:FindFirstChild("ValueFolder")
        if valueFolder then
            local tokenValue = valueFolder:FindFirstChild("Tokens")
            if tokenValue then
                tokenValue.Value += tokens
                print(player.Name .. " hat " .. tokens .. " Tokens gekauft! Neu: " .. tokenValue.Value)
            else
                warn("Tokens bei " .. player.Name .. " nicht gefunden")
            end
        else
            warn("ValueFolder bei " .. player.Name .. " nicht gefunden")
        end
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt