Buy Cash UI Not giving cash

Hello, I have added a Buy Cash GUI in my zed tycoon game. Everything works except for after I buy the product, it does not give my cash in my cash value.

This is my script for my cash button

And This is my purchase after its complete

And this is my Leaderstat value after the purchase(I already have 950K in my save database)

other forum topics seem to only solved this on old versions of the zed tycoon (I am using the new plasboer version)

If needed I can provide scripts of the tycoon itself.

6 Likes

I have made a value, but you can change it a bit if you want! but I think this will certainly works!

local MarketplaceService = game:GetService("MarketplaceService")

local productID = YOUR_PRODUCT_ID
local cashAmount = 100 -- The amount of in-game cash to give to the player upon purchase

local function giveCash(player)
    local cashValue = player:FindFirstChild("Cash")
    if not cashValue then
        cashValue = Instance.new("IntValue")
        cashValue.Name = "Cash"
        cashValue.Parent = player
    end

    cashValue.Value = cashValue.Value + cashAmount

    print(player.Name .. " received " .. cashAmount .. " in-game cash!")
end

local function onPromptGamePassPurchaseFinished(player, purchasedPassId, purchaseSuccess)
    if purchaseSuccess and purchasedPassId == productID then
        -- Check if the purchased pass ID matches the desired product ID
        giveCash(player)
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.promptGamePassPurchaseFinished:Connect(function(purchasedPassId, purchaseSuccess)
        onPromptGamePassPurchaseFinished(player, purchasedPassId, purchaseSuccess)
    end)
end)

-- Optional: Check if players already own the game pass when the server starts
game.Players.PlayerAdded:Connect(function(player)
    local ownPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, productID)
    if ownPass then
        giveCash(player)
    end
end)

4 Likes

So I used it your code but It still does not give me any cash.


I get a error 13:26:59.605 Players.TersaiIor.PlayerGui.TweenGuiTest.Frame1.TextButton.LocalScript:9: attempt to perform arithmetic (add) on string and number - Client - LocalScript:9

And a warning 13:27:04.072 Error occurred while processing a product purchase - Server - ReceiptHandler:135

3 Likes

its probably because you use the wrong type of value

im guessing because its a local script

On my first picture, it was clearly the correct value, considering the other pictures underneath it.

1 Like

So a normal script will have a different effect on the code than the local script?

wait did u add a player to the function

1 Like

try adding script.Parent.MouseButton1Click:connect(function(player)

I did try it with this script

local MarketplaceService = game:GetService(“MarketplaceService”)

local productID = 1563193650
local cashAmount = 1000000 – The amount of in-game cash to give to the player upon purchase

local function giveCash(player)
local cashValue = player:FindFirstChild(“Cash”)
if not cashValue then
cashValue = Instance.new(“IntValue”)
cashValue.Name = “Cash”
cashValue.Parent = player
end

cashValue.Value = cashValue.Value + cashAmount

print(player.Name .. " received " .. cashAmount .. " in-game cash!")

end

local function onPromptGamePassPurchaseFinished(player, purchasedPassId, purchaseSuccess)
if purchaseSuccess and purchasedPassId == productID then
– Check if the purchased pass ID matches the desired product ID
giveCash(player)
end
end

game.Players.PlayerAdded:Connect(function(player)
player.promptGamePassPurchaseFinished:Connect(function(purchasedPassId, purchaseSuccess)
onPromptGamePassPurchaseFinished(player, purchasedPassId, purchaseSuccess)
end)
end)

1 Like

i dont think a local script can change values on the server so try making it fire a remote function

1 Like

So would a code like this work? (Im a beginner so I use AI chat to help)

MPS = game:GetService(“MarketplaceService”)
id = 1563193650
local player = game.Players.LocalPlayer
– create a remote function
local cashUpdater = game.ReplicatedStorage:WaitForChild(“CashUpdater”)
script.Parent.MouseButton1Click:connect(function()
MPS:PromptProductPurchase(player, id)
– fire the remote function after the purchase
cashUpdater:FireServer(100000)
end)

– on the server-side, create the server script that listens for the remote function and updates the player’s cash
local cashUpdater = game.ReplicatedStorage:WaitForChild(“CashUpdater”)
cashUpdater.OnServerEvent:Connect(function(player, amount)
– update the player’s cash
player.leaderstat.Cash.Value = player.leaderstat.Cash.Value + amount
end)

(Did not work)

can u send it in the code format like this

MPS = game:GetService("MarketplaceService")
id = 1563193650
local player = game.Players.LocalPlayer
-- create a remote function
local cashUpdater = game.ReplicatedStorage:WaitForChild("CashUpdater")

script.Parent.MouseButton1Click:connect(function()
    MPS:PromptProductPurchase(player, id)
    -- fire the remote function after the purchase
    cashUpdater:FireServer(100000)
end) 

-- on the server-side, create the server script that listens for the remote function and updates the player's cash
local cashUpdater = game.ReplicatedStorage:WaitForChild("CashUpdater")
cashUpdater.OnServerEvent:Connect(function(player, amount)
    -- update the player's cash
    player.leaderstat.Cash.Value = player.leaderstat.Cash.Value + amount
end)

Try this is in server script service

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(recieptInfo)
	if recieptInfo.ProductId == YOUR_PRODUCT_ID then
		local plr = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
		plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value +AMMOUNT_HERE
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end
2 Likes

Still does not give me any cash after the purchase.

did you change any of the values

Yes i updated the Leaderstats to Leaderstat from your code to match my values.

what about in the script i just sent

you need to change product id and ammount