Help with developer products

local productFunctions = {}


productFunctions[1906083017] = function(receipt, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 300
		return true
	end
end

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then

		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then

			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end


	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt



```local script

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

local player = Players.LocalPlayer

local productId = 1906083017  


local function promptPurchase()
	MarketplaceService:PromptProductPurchase(player, productId)
end

script.Parent.MouseButton1Click:Connect(promptPurchase)





why is it not working

5 Likes

You are using a local script, and process receipt can only be done once by a server script. The only thing you should have on the local script is the prompt purchase, so just move the process receipt to the server and you should be good.

3 Likes

the process receipt is in a server script, everything thing works its just it doesnt give the player coins

3 Likes

Thats because your coins variable is defined as

leaderstats and leaderstats:FindFirstChild("Coins")

do

local coins = leaderstats:FindFirstChild("Coins")
4 Likes

I think that’s the same thing because the first one is just checking to see if leaderstats exists

6 Likes

still the same thing, nothing changed

4 Likes

Print coins and see what is being printed

4 Likes

nothing is being printed

productFunctions[1906083017] = function(receipt, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats:FindFirstChild("Coins")

	if coins then
		print(coins)
		coins.Value += 300
		return true
	end
end
3 Likes

put the print before the if statement since nothing is being printed it means that it didnt find coins in leaderstats make sure that everything is named correctly

3 Likes

nothing printed too

productFunctions[1906083017] = function(receipt, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats:FindFirstChild("Coins")

	print(coins)

	if coins then
		coins.Value += 300
		return true
	end
end
3 Likes

Ohhh bruh did you define MarketplaceService at the start of your server script?

3 Likes

yeah man here is the full script

local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local COINS_PER_MINUTE = 100
local BONUS_COINS_GAMEPASS = 1000
local GAMEPASS_ID = 885153406  


local function loadPlayerData(player)
	local playerKey = "Player_" .. player.UserId
	local defaultData = {
		Coins = 0,
		TimePlayed = 0,
	}

	local success, playerData = pcall(function()
		return playerDataStore:GetAsync(playerKey)
	end)

	if success and playerData then
		return playerData
	else
		return defaultData
	end
end

local function savePlayerData(player, playerData)
	local playerKey = "Player_" .. player.UserId

	local success, err = pcall(function()
		playerDataStore:SetAsync(playerKey, playerData)
	end)

	if not success then
		warn("Failed to save data for " .. player.Name .. ": " .. tostring(err))
	end
end


local function onPlayerAdded(player)
	local playerData = loadPlayerData(player)


	local ownsGamePass = false
	local success, err = pcall(function()
		ownsGamePass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, tostring(GAMEPASS_ID))
	end)

	if success and ownsGamePass then
		playerData.Coins = playerData.Coins + BONUS_COINS_GAMEPASS
		savePlayerData(player, playerData)  -- Save immediately after adding bonus coins
	end

	-- Create leaderstats
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	-- Coins
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = playerData.Coins
	coins.Parent = leaderstats

	-- Time Played
	local timePlayed = Instance.new("IntValue")
	timePlayed.Name = "TimePlayed"
	timePlayed.Value = playerData.TimePlayed
	timePlayed.Parent = leaderstats

	
	local function giveCoinsAndUpdateTime()
		while true do
			local bonusCoins = 0

			-- Check if player owns the game pass
			local success, ownsGamePass = pcall(function()
				return MarketplaceService:UserOwnsGamePassAsync(player.UserId, tostring(GAMEPASS_ID))
			end)

			if success and ownsGamePass then
				bonusCoins = BONUS_COINS_GAMEPASS
			end
			if not ownsGamePass then
				print("not")
			end

			playerData.Coins = playerData.Coins + COINS_PER_MINUTE + bonusCoins
			coins.Value = playerData.Coins

			playerData.TimePlayed = playerData.TimePlayed + 1  
			timePlayed.Value = playerData.TimePlayed

			savePlayerData(player, playerData)
			wait(60)  -- Wait for 60 seconds (1 minute)
		end
	end
	
	spawn(giveCoinsAndUpdateTime)
	
end



local productFunctions = {}


productFunctions[1906083017] = function(receipt, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats:FindFirstChild("Coins")


	if coins then
		coins.Value += 300
		return true
	end
end

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then

		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then

			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end


	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt







local function onPlayerRemoving(player)
	local playerData = {
		Coins = player.leaderstats.Coins.Value,
		TimePlayed = player.leaderstats.TimePlayed.Value,
	}

	savePlayerData(player, playerData)
end

-- Connect events
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)



3 Likes

Try putting a print in processreceipt to see if that even fires

3 Likes

Is ‘Coins’ A NumberValue?

Yes

Do

print(Coins.Value)

You are trying to print an instance with your current script

3 Likes

its an int value not a Number value

3 Likes

it doesnt do anything.

ocal function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then

		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			
		print("Success")
		
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end


	return Enum.ProductPurchaseDecision.NotProcessedYet
end
1 Like

Put it at the start of processreceipt again to make sure, if it doesnt then processreceipt isnt firing at all

2 Likes

If it is an IntValue OR a NumberValue, do what they says. If its an integer and NOT a value (which can’t be displayed on the leaderboard), then you don’t have to, but you most likely still have to do what they said.

1 Like

yeah its not firing what do i do

local function processReceipt(receiptInfo)
	print("Success")
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then

		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			
		
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end


	return Enum.ProductPurchaseDecision.NotProcessedYet
end

Try calling the purchase prompt on the server