#Changing a value after buying a dev product

12 messages · Page 1 of 1 (latest)

wanton quail
#

So I have this problem: Another script saves am IntValue inside of a Folder called "PlayerCash", this IntValue has the name of the player and its value is how much cash he has (Screenshot attached). Now, I wanted to implement a way to change the players cash after he bought a dev product. The script I put below was my solution to this, but it does not work.

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local SpecificProductID = "1809362370"

local function processReceipt(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerID = receiptInfo.PlayerId

    local playerName
    pcall(function()
        playerName = Players:GetNameFromUserIdAsync(playerID)
    end)

    local playerCash = ServerStorage:FindFirstChild("PlayerCash")

    if productId == SpecificProductID then
        if playerName then
            if playerCash then
                local cashValue = playerCash:FindFirstChild(playerName)
                if cashValue and cashValue:IsA("IntValue") then
                    cashValue.Value = cashValue.Value + 1000
                else
                    warn("Cash value not found or not an IntValue for player: " .. playerName)
                end
            else
                warn("PlayerCash not found in ServerStorage.")
            end
        else
            warn("Failed to get player name from PlayerId: " .. playerID)
        end
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

game:GetService("MarketplaceService").ProcessReceipt = processReceipt```
#

It doesnt give me any errors, so I have nothing to work with..

distant lakeBOT
#

studio** You are now Level 4! **studio

digital silo
#

I'm new to scripting myself but let's see what I can do here

#

cashValue.Value = cashValue.Value + 1000, u can change that to just cashValue.Value += 1000

its simpler and doesnt take much space

anyway back to your error. Try debugging and if that doesnt work then maybe the other script is interfering with it somehow, or make a remote function

distant lakeBOT
#

studio** You are now Level 1! **studio

wanton quail
#

Sorry, I dont know yet as I havent been able to test what GreenShadow said

#

I will be able to in about 30 minutes to an hour

#

But if you have an Idea, go ahead

#

That would be great

#

Take as long as you need