#Marketplace Issue

1 messages · Page 1 of 1 (latest)

blissful swift
#

So the code works in single test but it doesnt work if I do it on team test. Why?

#
local PoppyseedPackStand = workspace:WaitForChild("PoppyseedPackStand")
local limitText = PoppyseedPackStand:WaitForChild("Title"):WaitForChild("LimitGui"):WaitForChild("LimitText")
local stockProductId = 3403510225
local maxStock = 7000
local stockKey = "PoppyseedStock"
local dataStore = DataStoreService:GetDataStore("GlobalShopStock")
local currentStock = maxStock
local stockLock = false

local CheckCapacity = events:WaitForChild("CheckCapacity")
local UpdateStockEvent = events:WaitForChild("UpdateStockEvent")
local ManualPurchase = events:WaitForChild("ManualPurchase")
local RestockEvent = events:WaitForChild("RestockSeedPack")

local function loadStock()
    local success, saved = pcall(function()
        return dataStore:GetAsync(stockKey)
    end)
    if success and type(saved) == "number" then
        currentStock = saved
    else
        currentStock = maxStock
    end
end
#
local function saveStock()
    pcall(function()
        dataStore:SetAsync(stockKey, currentStock)
    end)
end

local function updateStock()
    if currentStock > 0 then
        limitText.Text = string.format("%d/%d LEFT", currentStock, maxStock)
    else
        limitText.Text = "SOLD OUT"
    end
    UpdateStockEvent:FireAllClients(currentStock, maxStock)
end

local function processPurchase()
    if stockLock then return false end
    stockLock = true
    if currentStock > 0 then
        currentStock -= 1
        updateStock()
        saveStock()
        stockLock = false
        return true
    else
        stockLock = false
        return false
    end
end

local function restock()
    if stockLock then return false end
    stockLock = true
    currentStock = maxStock
    updateStock()
    saveStock()
    stockLock = false
end

loadStock()
updateStock()
#
MarketplaceService.ProcessReceipt = function(receiptInfo)
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
    
    while not data[player.UserId] and player.Parent do
        task.wait(0.1)
    end
    local playerData = data[player.UserId]
    if not playerData then return Enum.ProductPurchaseDecision.NotProcessedYet end

    if receiptInfo.ProductId == stockProductId then
        local bought = processPurchase()
        if bought then
            pcall(function()
                insertPiggy(player, "Mr. P")
                insertPiggy(player, "Mrs. P")
            end)
            
            local plot = getAssignedPlot(player)
            if plot then refreshPlot(plot) end
            
            events.ShowNotification:FireClient(player, "Purchase Success!", "Purchase")
        else
            events.ShowNotification:FireClient(player, "Out of Stock!", "Error")
        end
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

CheckCapacity.OnServerInvoke = function(player)
    return currentStock > 0
end

ManualPurchase.OnServerEvent:Connect(function(player)
    if player.Name == "Incidus_RBLX" then
        processPurchase()
    end
end)

RestockEvent.OnServerEvent:Connect(function(player)
    if player.Name == "Incidus_RBLX" then
        currentStock = maxStock
        updateStock()
        saveStock()
    end
end)

game:BindToClose(saveStock)
dry flint
#

copying grow a garden aint so simple as it seems ey

dry flint
blissful swift
#

It works in single player but it doesnt work when im in team test

dry flint
#

i can't stream video you'll have to explain it using your words

blissful swift
#

Or is this just a studio bug 😕

blissful swift
#

I did
local data = {}
and when Im loading the data i do
data[player.UserId] = playerData

#

But its prob too long I cant send it

dry flint
#

you can send messages too long discord attaches it as txt

blissful swift
dry flint
#

where call loaddata

blissful swift
#

Players.PlayerAdded:Connect(loadData)

dry flint
#

i suggest add prints to see whats running and what is not around processreceipt

blissful swift
#

Alr

dry flint
#

y'know, beginner debugging

blissful swift
#

Ok this gotta be a studio bug 💀