Why doesnt this developer product work?

A lot of people are disliking my game because my developer product doesn’t do anything, please help:

MarketService.ProcessReceipt = function(receipt)


			local ID = receipt.PlayerId.."-"..receipt.PurchaseId

			local sucess = nil

			pcall (function()

				sucess = PreviousPurhcases:GetAsync(ID)
			end)


			if sucess then



				return Enum.ProductPurchaseDecision.PurchaseGranted

			end



			local player = game.Players:GetPlayerByUserId(receipt.PlayerId)


			if not player then


				return Enum.ProductPurchaseDecision.NotProcessedYet


			else		

				if receipt.ProductId == Fifty_Coins then
					playerData.Stars += 50
				end

				if receipt.ProductId == Hundred_Coins then
					playerData.Stars += 100
				end

				pcall(function()
					PreviousPurhcases:SetAsync(ID,true)
				end)
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end

Any help is really appreciated!

3 Likes

Here’s the documentation of developer products. There are scripts and descriptions of what those scripts do.

1 Like

Are you sure that you haven’t used multiple Scripts with ProcessReceipt? If true, it seems to be causing an issue because Roblox depends on a single script to handle the function.

To provide further assistance, it would be helpful if you could provide additional context or specific details about the problem you are experiencing.

1 Like

No, this is the only script using ProcessReceipt, for more context, this is what the data table looks like,

playerData = {
				["Stars"] = 0,
				["SelectedTowers"] = {"CCTV-Man","TV-Man"},
				["OwnedTowers"] = {"CCTV-Man","TV-Man"},
			}

And this is the whole script (runs when a player is added)

local function loadData(player)
	local success = nil
	local playerData = nil
	local attempt = 1

	repeat
		success, playerData = pcall(function()
			return dataBase:GetAsync(player.UserId)
		end)

		attempt += 1
		if not success then
			warn(playerData)
			task.wait()
		end
	until success or attempt == 3

	if success then
		print("Connection success")
		if not playerData then
			print("New player, giving default data")
			playerData = {
				["Stars"] = 0,
				["SelectedTowers"] = {"CCTV-Man","TV-Man"},
				["OwnedTowers"] = {"CCTV-Man","TV-Man"},
			}
		end
		data[player.UserId] = playerData
		
		local function FinishedGamepassPrompt(player, purchaseId, purchased)
			if purchased then
				if purchaseId == TitanTVManID then
					table.insert(playerData.OwnedTowers, "Titan TV-Man")
					player:Kick("Rejoin to use gamepass")
				end
			end
		end
		
		MarketService.ProcessReceipt = function(receipt)


			local ID = receipt.PlayerId.."-"..receipt.PurchaseId

			local sucess = nil

			pcall (function()

				sucess = PreviousPurhcases:GetAsync(ID)
			end)


			if sucess then



				return Enum.ProductPurchaseDecision.PurchaseGranted

			end



			local player = game.Players:GetPlayerByUserId(receipt.PlayerId)


			if not player then


				return Enum.ProductPurchaseDecision.NotProcessedYet


			else		

				if receipt.ProductId == Fifty_Coins then
					playerData.Stars += 50
				end

				if receipt.ProductId == Hundred_Coins then
					playerData.Stars += 100
				end

				pcall(function()
					PreviousPurhcases:SetAsync(ID,true)
				end)
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end

		MarketService.PromptGamePassPurchaseFinished:Connect(FinishedGamepassPrompt)
		
		if MarketService:UserOwnsGamePassAsync(player.UserId, TitanTVManID) then
			if not table.find(playerData.OwnedTowers, "Titan TV-Man") then
				table.insert(playerData.OwnedTowers, "Titan TV-Man")
			end
		end
		
		if player.UserId == 755336343 or player.UserId == 3043450659 then
			if not table.find(playerData.OwnedTowers, "TitanSpeakerman") then
				table.insert(playerData.OwnedTowers, "TitanSpeakerman")
			end
			
			if not table.find(playerData.OwnedTowers, "Scientist Cameraman") then
				table.insert(playerData.OwnedTowers, "Scientist Cameraman")
			end
		end
		if player.UserId == 1317259399 then
			print("OWNER JOINED!")
			playerData = {
				["Stars"] = 9999,
				["SelectedTowers"] = {"CCTV-Man","Speakerman","TitanSpeakerman"},
				["OwnedTowers"] = {"CCTV-Man","Speakerman","TitanSpeakerman"},
			}
			data[player.UserId] = playerData
			
			for i, plr in pairs(game.Players:GetPlayers()) do
				badgeService:AwardBadge(plr.UserId, 2147813704)
			end
		end

	else
		warn("Unable to get data for player", player.UserId)
		player:Kick("There was a problem getting your data")
	end
end
1 Like

Is it possible that you could give me the whole script?!

Sure. Here is is (Its from Gnomecode’s tutorial)

local DataStoreService = game:GetService("DataStoreService")
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local badgeService = game:GetService("BadgeService")
local RunService = game:GetService("RunService")

local dataBase = DataStoreService:GetDataStore("database")
local towers = require(replicatedStorage:WaitForChild("TowerShop"))

local PreviousPurhcases = DataStoreService:GetDataStore("PreviousPurchases")


local TitanTVManID = 196249150

local Fifty_Coins = 1566978490

local Hundred_Coins = 1566981869


local MAX_SELECTED = 3
local data = {}



--load player data
local function loadData(player)
	local success = nil
	local playerData = nil
	local attempt = 1

	repeat
		success, playerData = pcall(function()
			return dataBase:GetAsync(player.UserId)
		end)

		attempt += 1
		if not success then
			warn(playerData)
			task.wait()
		end
	until success or attempt == 3

	if success then
		print("Connection success")
		if not playerData then
			print("New player, giving default data")
			playerData = {
				["Stars"] = 0,
				["SelectedTowers"] = {"CCTV-Man","TV-Man"},
				["OwnedTowers"] = {"CCTV-Man","TV-Man"},
			}
		end
		data[player.UserId] = playerData
		
		local function FinishedGamepassPrompt(player, purchaseId, purchased)
			if purchased then
				if purchaseId == TitanTVManID then
					table.insert(playerData.OwnedTowers, "Titan TV-Man")
					player:Kick("Rejoin to use gamepass")
				end
			end
		end
		
		MarketService.ProcessReceipt = function(receipt)


			local ID = receipt.PlayerId.."-"..receipt.PurchaseId

			local sucess = nil

			pcall (function()

				sucess = PreviousPurhcases:GetAsync(ID)
			end)


			if sucess then



				return Enum.ProductPurchaseDecision.PurchaseGranted

			end



			local player = game.Players:GetPlayerByUserId(receipt.PlayerId)


			if not player then


				return Enum.ProductPurchaseDecision.NotProcessedYet


			else		

				if receipt.ProductId == Fifty_Coins then
					playerData.Stars += 50
				end

				if receipt.ProductId == Hundred_Coins then
					playerData.Stars += 100
				end

				pcall(function()
					PreviousPurhcases:SetAsync(ID,true)
				end)
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end

		MarketService.PromptGamePassPurchaseFinished:Connect(FinishedGamepassPrompt)
		
		if MarketService:UserOwnsGamePassAsync(player.UserId, TitanTVManID) then
			if not table.find(playerData.OwnedTowers, "Titan TV-Man") then
				table.insert(playerData.OwnedTowers, "Titan TV-Man")
			end
		end
		
		if player.UserId == 755336343 or player.UserId == 3043450659 then
			if not table.find(playerData.OwnedTowers, "TitanSpeakerman") then
				table.insert(playerData.OwnedTowers, "TitanSpeakerman")
			end
			
			if not table.find(playerData.OwnedTowers, "Scientist Cameraman") then
				table.insert(playerData.OwnedTowers, "Scientist Cameraman")
			end
		end
		if player.UserId == 1317259399 then
			print("OWNER JOINED!")
			playerData = {
				["Stars"] = 9999,
				["SelectedTowers"] = {"CCTV-Man","Speakerman","TitanSpeakerman"},
				["OwnedTowers"] = {"CCTV-Man","Speakerman","TitanSpeakerman"},
			}
			data[player.UserId] = playerData
			
			for i, plr in pairs(game.Players:GetPlayers()) do
				badgeService:AwardBadge(plr.UserId, 2147813704)
			end
		end

	else
		warn("Unable to get data for player", player.UserId)
		player:Kick("There was a problem getting your data")
	end
end
Players.PlayerAdded:Connect(loadData)

--save player data
local function saveData(player)
	if data[player.UserId] then
		local success = nil
		local playerData = nil
		local attempt = 1

		repeat
			success, playerData = pcall(function()
				return dataBase:UpdateAsync(player.UserId, function()
					return data[player.UserId]
				end)
			end)

			attempt += 1
			if not success then
				warn(playerData)
				task.wait()
			end
		until success or attempt == 3

		if success then
			print("Data saved successfully")
		else
			warn("Unable to save data for player", player.UserId)
		end
	else
		warn("No session data for", player.UserId)
	end
end
Players.PlayerRemoving:Connect(function(player)
	saveData(player)
	data[player.UserId] = nil
end)

game:BindToClose(function()--if game shuts down
	if not RunService:IsStudio() then
		print("Shutting down")
		for index, player in pairs(Players:GetPlayers()) do
			task.spawn(function()
				saveData(player)
			end)
		end
	else
		print("Shutting down inside studio")
	end
end)

local function getItemStatus(player,itemName)
	local playerData = data[player.UserId]
	if table.find(playerData.SelectedTowers, itemName) then
		return "Equipped"
	elseif table.find(playerData.OwnedTowers, itemName) then
		return "Owned"
	else
		return "For Sale"
	end
end


replicatedStorage.InteractItem.OnServerInvoke = function(player, itemName)
	local shopItem = towers[itemName]
	local playerData = data[player.UserId]
	if shopItem and playerData then--if it exists and player has some data
		local status = getItemStatus(player,itemName)
		
		if status == "For Sale" and shopItem.Price <= playerData.Stars then
			--purchase
			playerData.Stars -= shopItem.Price
			table.insert(playerData.OwnedTowers, shopItem.Name)
		elseif status == "Owned" then
			--equip the tower
			table.insert(playerData.SelectedTowers, shopItem.Name)
			if #playerData.SelectedTowers > MAX_SELECTED then
				table.remove(playerData.SelectedTowers, 1)
			end
		elseif status == "Equipped" then
			--unselect(if more that 1 selected)
			if #playerData.SelectedTowers > 1 then
				local towerToRemove = table.find(playerData.SelectedTowers, itemName)
				table.remove(playerData.SelectedTowers, towerToRemove)
			end
		end
		
		return playerData
	else
		warn("Tower/player data does not exist")
	end
	return false--if something went wrong
end

replicatedStorage.GetData.OnServerInvoke = function(player)
	return data[player.UserId]
end

And heres the prompt

local MarketPlaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
	MarketPlaceService:PromptProductPurchase(player,1566978490)
end)

1 Like

I just joined your game and saw that it’s from GnomeCode, I’m trying my best to find the issue

If you want, you can replace it with that and put the Value Adding into it

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

local PID = 0 -- Your ProductId

local function proccess(receiptinfo)
	local player = Players:GetPlayerByUserId(receiptinfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptinfo.ProductId == PID then
		if player then
			-- Your Action
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = proccess

If I understand that right. You are prompting a ProductPurchase if a player clicks a TextButton or Image button. Is the button Property Active set to true?!

Whats the difference in this and mine? I tried it out and it seemed to work in studio but that was the same case with the other one where it works in studio and not game, though I haven’t tested this one yet.

To be honest, I don’t know lol. I just made it, and now if I am looking right. I think it is similiar, but how do you know that it isn’t working ingame