ProcessReceipt working in studio but ingame

Hi there! I have a question, I am currently working on a donation board for my Difficulty Chart Obby, now, the problem is that the script simply does not work ingame, but it does in Studio. The skip stage part works, but if someone donated, the amount doesn’t get added to the board his datastore.

Script:

local SkipId = 1137658844
local Players = game:GetService("Players")
local Products = require(game.Workspace.Boards.Products)

local function processReceipt(receiptInfo)
	local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptInfo.ProductId == SkipId then
		plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
		plr.TeleportedStage.Value = plr.TeleportedStage.Value + 1
		wait(.1)
		plr:LoadCharacter()
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		local function GetData()
			local Datastore = game:GetService("DataStoreService"):GetDataStore("BoardData")
			local Data = Datastore:GetAsync("Data")
			if Data == nil then
				Data = {ListSize = 30, Datastore = 1, Refresh = 1, Version = 2}
			end

			local TD = "TopDonators"

			if Data.Datastore ~= 1 then
				TD = "TopDonators"..Data.Datastore
			end

			return TD
		end
		local PlayerFound = false
		for i, v in pairs (game.Players:GetChildren()) do
			if v:IsA('Player') then
				if v.userId == receiptInfo.PlayerId then
					for _, p in pairs (Products.Products) do
						if p.ProductId == receiptInfo.ProductId then
							if v ~= nil then
								PlayerFound = true
								game:GetService("DataStoreService"):GetOrderedDataStore(GetData()):IncrementAsync(receiptInfo.PlayerId, p.ProductPrice)
							end
						end
					end
				end
			end
			wait(2)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end





--Set Callback
local mps = game:GetService("MarketplaceService")
mps.ProcessReceipt = processReceipt

Recently, I have had the same problem as you. Are you trying to do it in a team create or local server? If so, then it will not work.

1 Like

Roblox SAYS you should have only one script for ProcessReceipt, just a warning; Just something, OrderedDataStores aren’t compatible with stuff which isn’t integers; I’m confused at your script but yeah;

The game is published already, and i’m trying to make it in team create, yes.

Hey @NotBleep.

Wew there’s a lot going on here, let’s try to cut some of it down.

I believe your issue is in your various and many impractical uses of syntax.

What I mean is, well here’s an itemized list of everything I spotted:

  • Creating a function inside of another???
  • Getting your datastore in the function (bad call)
  • Using :GetChildren() on players and testing if they’re players.
  • Getting the same datastore again??? to set the value??

So because of all of that I think that Roblox might be confused as to what you’re trying to do, and frankly I don’t know how to even begin helping you fix it all, it’s like hardcore messed up.

I’m seriously not trying to be mean here, but where did you learn to script like that?

1 Like