DevProduct Script not giving the product after purchase

Sorry, I have been creating a lot of topics lately but I am learning to script so yea you run into loads of errors when you are learning. Well, my dev product script is not giving the product even after the purchase is successful. Here are the scripts

DevProduct Prompter Script

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

    local productID = 1075471951  
    local player = game.Players.LocalPlayer 

    wait (3)

    MarketPlaceService:PromptProductPurchase(player , productID) 
____________________________________________________________________________

The DevProductHandeler (This is where I am getting the error) 

   local MarketPlaceService = game:GetService("MarketplaceService") 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local gun = game.ReplicatedStorage:WaitForChild("ClassicPaintballGun")
local players = game:GetService("Players") 


local productID = 1075471951 

local function processReceipt(receiptInfo) 
	local player = players:GetPlayerByUserId(receiptInfo.playerId) 
	if not player then 
		--the player probably left the game 
		--If they come back ,the callback will be called again 
		
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end 
	
	if player then 
		--what do u want the devproduct to do  
		local char = game.Workspace:FindFirstChild(player.Name)
		local gunClone = gun.clone() 
		gunClone.Name = gun 
		gunClone.Parent = char
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
	
end 

--Set callback 
MarketPlaceService.ProcessReceipt = processReceipt() 

This is the error i am getting

2 Likes

Try using UserId instead of PlayerId. That should solve the problem.

Umm its still not working i have replaced playerId with UserId as you said

1 Like

Can you show me whats in the output?

here is the output

Sol3

Alright so maybe try reading this article: MarketplaceService | Documentation - Roblox Creator Hub
At the Bottom are some examples for usage.

Oh nevermind i see you said local Players =
But you used players:. I guess you can just do Players instead of players. Line 10

can u modify the scirpt with the fix for refrence?

Sure, i can do that in a bit. Just keep a eye on this thread.

2 Likes
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Gun = ReplicatedStorage:WaitForChild("ClassicPaintballGun")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1075471951 then
		local Player = Players:GetPlayerByUserId(receiptInfo.PlayerId) -- Apparently its PlayerId lol sorry.
		if Player then
			repeat wait() until workspace:FindFirstChild(Player.Name) -- Just for safety.
			local Character = workspace[Player.Name]
			local gun = Gun:Clone()
			gun.Parent = Player:WaitForChild("Backpack") -- Instead of the Character, he has it in his inventory.
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end

This should work, i hope you understand everything. I had no problems while testing it.

3 Likes

yes thanks a lot its working! :grinning: