DevProduct works ony in Studio

  1. Trying to make pay to respawn GUI system with saves player tools. (DevProduct)

  2. DevProduct works only in Studio, not working in team test or real game.

  3. I was looking for similar topics but didn’t find anything helpful

Output prints only “2 complete” and then stops, why ProcessRecipt not working? (only Team Test, in Studio everything works well). You can see below ↓

Item saving after death script + checking if player bought devProduct ↓

local Players = game:GetService("Players")
local Market = game:GetService("MarketplaceService")


function OnPlayerAdded(Player)
	print("OnPlayerAdded (1) - complete")
	local SavedTools = {}

	local function OnCharacterAdded(Character)
		print("OnCharacterAdded (2) - complete")
		
		Market.ProcessReceipt = function(recieptInfo)
			print("Market (3) - complete")
			if recieptInfo.ProductId == 1842353716 then
				print("if ProductId (4) - complete")
				local player = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
				print(player)
				player:LoadCharacter()
				for Index, Tool in pairs(SavedTools) do --Loads all the saved tools from the player's last death
					Tool.Parent = Player.Backpack
					
				end
				
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end
		SavedTools = {}

		
		 



		local function OnDied() --Copies all your tools when you die and saves them to a table attached to the player
			print('onDied 1')
			for Index, Tool in pairs(Player.Backpack:GetChildren()) do
				local CopiedTool = Tool:Clone()
				table.insert(SavedTools, CopiedTool)
			end

			for Index, Tool in pairs(Player.Character:GetChildren()) do --Checks if theres a tool being currently used/equipped by the player
				if Tool:IsA("Tool") then
					local CopiedTool = Tool:Clone()
					table.insert(SavedTools, CopiedTool)
				end
			end
		end

		Character.Humanoid.Died:Connect(OnDied)

	end

	Player.CharacterAdded:Connect(OnCharacterAdded)

end

for Index, Player in pairs(Players:GetChildren()) do --Redundency incase a player has joined before the event sets up
	OnPlayerAdded(Player)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

Dev Product button: ↓


local Market = game:GetService("MarketplaceService")
local id = 1842353716
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	Market:PromptProductPurchase(player, id)
end)

Any ideas whats wrong?

You are reassigning ProcessReceipt each time the character loads, using a blank table each time. This is not how ProcessReceipt should be implemented, and is the reason why it only works for one player.

You should use an entirely different script, and I would recommend this structure:

local players = game:GetService("Players")
local mps = game:GetService("MarketplaceService")

local productFuncs = {} --to hold what each of your products do. You could put this in a module.

productFuncs[YourProductIdGoesHere] = function(player)
    --grant the player their rewards
    return true
end

--process the receipt
local function process(info)
    --get the player and the handler
    local player = players:GetPlayerByUserId(info.PlayerId)
    local product = productFuncs[info.ProductId]

    --use a pcall to catch errors (like if the player leaves)
    local success, result = pcall(handler, player)
    
    if success then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    else
        return Enum.ProductPurchaseDecision.NotProcessedYet --retry when they next join
    end
end

mps.ProcessReceipt = process --set the callback

This fixes the problem of using a different table of tools each time for players, but you will need a way to get their tools individually. I took this structure from the documentation.

1 Like