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```
** You are now Level 4! **