Buy buttons not working

If the issue persists and using pcall doesn’t resolve the situation because the problem lies with the function call itself returning nil or not behaving as expected, we need to adjust the approach to explicitly handle the possibility of nil values or ensure that the operation inside the pcall can successfully complete.

local bb = option.BuyButton

local function attemptPurchase()
    local toServerFunction = Functions:WaitForChild("ToServer", 10) -- waits up to 10 seconds for the child
    if not toServerFunction then
        UpdateText(bb, "Server error. Please try again.", 2)
        return
    end
    
    local result
    local success, errorMessage = pcall(function()
        result = toServerFunction:InvokeServer("PurchaseItem", tool.Name)
    end)

    if success and result then
        if result == "Success" then
            UpdateText(bb, "Purchase complete!", 2)
            return true
        elseif result == "Failure" then
            UpdateText(bb, "Insufficient funds", 2)
        else
            UpdateText(bb, "Unexpected error: " .. result, 2)
        end
    else
        UpdateText(bb, "Failed to communicate with server: " .. (errorMessage or "Unknown error"), 2)
    end
    
    return false
end

-- Attempt to make the purchase, retry once if it fails
if not attemptPurchase() then
    wait(1) -- Wait for a second before retrying
    attemptPurchase() -- Retry the purchase once
end

lol, I’m just tryna make an invoke to the server I don’t think that much would be necessary to make my script function, I need to find whats stopping my code.

You might need to further diagnose but just try finding the error or maybe you’re right about purchase items not working ??

I created a new remote function and it worked, I don’t know why.

Looks like i’ll just use different remote functions for now. I was using a remote function for shop purchases and an NPC who handled upgrades.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.