Purchasing in-game currency issue

i have noticed that many players purchasing in-game currency using robux have not gotten their in-game currency. i tested it in the studio and it works but not when playing the game off the studio

here are two screenshots. one includes the script that is in the GUI button and one in serverscriptservice

the button script

the script in serverscriptservice

and what could be the issue? it doesn’t make sense that the fact it works in studio and not in the game off of studio

and don’t worry, I’ve been giving every player that purchased in-game currency their currency they purchased for

Can you copy and paste the server-script here so it’s easier to edit for us?

sure, here it is

local MPS = game:GetService("MarketplaceService")

local BossEvent = game.ReplicatedStorage.Remotes:WaitForChild("BecomingBossZombie")

MPS.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1210145816 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
		return Enum.ProductPurchaseDecision.PurchaseGranted

	elseif receiptInfo.ProductId == 1210145964 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 500
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146040 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146121 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1500
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146196 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146257 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146331 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 50000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146416 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1210146498 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1000000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptInfo.ProductId == 1254630347 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.PlayerGui.ConfirmationGui.Frame.Visible = true
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

Try this to replace it:

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

--//Tables
local productFunctions = {}

--//Functions
productFunctions[1210145816] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 100
	
	return true
end

productFunctions[1210145964] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 500

	return true
end

productFunctions[1210146040] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 1000

	return true
end

productFunctions[1210146121] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 1500

	return true
end

productFunctions[1210146196] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 5000

	return true
end

productFunctions[1210146257] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 10000

	return true
end

productFunctions[1210146331] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 50000

	return true
end

productFunctions[1210146416] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 100000

	return true
end

productFunctions[1210146498] = function(receipt, player)
	local Cash = player.leaderstats.Cash
	Cash.Value += 1000000

	return true
end

productFunctions[1210146416] = function(receipt, player)
	local PlayerGui = player.PlayerGui
	PlayerGui.ConfirmationGui.Frame.Visible = true

	return true
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local Function = productFunctions[receiptInfo.ProductId]

	local success, result = pcall(Function, receiptInfo, player)

	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)

		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

this has literally been happening to me too, omg.

when i purchased one of the product, it doesn’t give me the cash

I’m assuming this is the one which doesn’t give you cash?

when a player purchases that product, they will receive that gui listed in the code. all of the other products than this one give the player their cash. so no

1 Like

I think it’s just a roblox issue tbh rather than a scripts fault.

probably but it turned out this problem has been happening to my game for weeks so I am sure roblox would have already fixed the problem, that as if I knew

I have had a terrible time with ProcessReciept. There was once a big issue where the entire system broke down completely when Pet Simulator X breaking completely destroyed my datastores. Here’s what I do in my processreciept callback:

local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local tries = 0
	while not plr and tries < 20 do
		wait(0.2)
		plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		tries = tries + 1
	end

i also log the purchase id to make sure there are no duplicate attempts.

you should also make sure that you SAVE YOUR DATA IMMEDIATELY when a player purchases currency.

when setting up a currency purchase system, you can make a function that returns the correct amount of currency instead of copy pasting the same code. e.g.

function WowGetMyCoins(ID)
	if ID == 2123 then
		return 10 -- 10 coins for that product
	elseif ID == 299239 then
		return 22222
	end
end
local Coins = WowGetMyCoins(receiptInfo.ProductId)
if Coins then
	player.Data.Coins.Value += Coins
	warn( 'Yay!!!!!' )
	return Enum.ProductPurchaseDecision.PurchaseGranted
else
	return Enum.ProductPurchaseDecision.NotProcessedYet
end
2 Likes

welp, it is not working either but I appreciate it

local Game = game
local Players = Game:GetService("Players")
local Marketplace = Game:GetService("MarketplaceService")

local Products = {[1210145816] = 100, [1210145964] = 500, [1210146040] = 1000, [1210146121] = 1500, [1210146196] = 5000, [1210146257] = 10000, [1210146331] = 50000, [1210146416] = 100000, [1210146498] = 1000000}
local True, False = Enum.ProductPurchaseDecision.PurchaseGranted, Enum.ProductPurchaseDecision.NotProcessedYet

local function OnProcessReceipt(ReceiptInfo)
	local Value = Products[ReceiptInfo.ProductId]
	if not Value then return False end
	local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
	if not Player then return False end
	local leaderstats = Player:FindFirstChild("leaderstats")
	if not leaderstats then return False end
	local Cash = leaderstats:FindFirstChild("Cash")
	if not Cash then return False end
	Cash.Value += Value
	return True
end

Marketplace.ProcessReceipt = OnProcessReceipt

Might be worth learning tables.

it works, but once again, only in the studio and not in-game

I’m not sure why that would be the case, perhaps your game contains some malicious code that is only executed in live sessions, ‘virus’ developers may do this in order to hide their scripts.

why won’t you make a game, with a button, 1 robux dev product for 100 leaderstat coins, and make it uncopylocked. so we know if the fault is on our end, or it’s for everyone

good news, i found a solution!