ProcessReceipt script not working

Why won’t this script work?

local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local ProductID = 1190752185 --Type DEV id here

local function processReceipt(receiptInfo)
   
   local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
   if not player then
   	return Enum.ProductPurchaseDecision.NotProcessedYet
   end

   	Replicated.HINTS.Level1:FireClient(game:GetService("Players"))
   end

   MarketPlaceService.ProcessReceipt = processReceipt```

You’ve created a function but not using it, how can it work? Make sure to connect it whenever a event fired.

1 Like

You can use MarketplaceService.PromptPurchaseFinished to make this work, this will detect when someone purchases your DevProduct.

1 Like

how would I put that into my script?

Humm, this should work.

local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local ProductID = 1190752185 --Type DEV id here

local function ProductPurchase(player, assetId, isPurchased)
     if assetId == ProductID then
          if isPurchased == true then
                print("Purchased")
                -- Your script goes here
          end
     end
end

MarketplaceService.PromptPurchaseFinished:Connect(ProductPurchase)

You can use a BindableEvent | Roblox Creator Documentation for this. I do not recommend doing this client side because it will not be secure and will be vulnerable to exploiters.

Why do you have a service in the first parameter? You mean a player?

Error “Players.joshuaThe5th.PlayerGui.HINTGUI.TextButton.Frame.Shop.TextButton.LocalScript:15: attempt to index nil with ‘PromptPurchaseFinished’”

My bad, create a MarketplaceService variable by doing local MarketplaceService = game:GetService("MarketplaceService"). You can place at the start of the script.

that will work, now I have to make it work with a button

Make a ClickDetector, then detect when someone clicked it prompt the DevProduct out.

couldn’t I just use a text button and use button.Mousebutton1click??

Yes you can do with it. And I have a better script here.

local MarketplaceService = game:GetService("MarketplaceService")
local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local ProductID = 1190752185 --Type DEV id here

local function ProductPurchase(userId, assetId, isPurchased)
     if assetId == ProductID then
          if isPurchased == true then
                print("Player "..userId.." purchased a product which has id "..assetId)
                -- Your script goes here
          end
     end
end

MarketplaceService.PromptProductPurchaseFinished:Connect(ProductPurchase)

So I just done a research, PromptProductPurchaseFinished would be better.

how would I add the button into the script?

If you want to use with TextButton, create a LocalScript inside the button you want to use. Then use this script.

local MarketplaceService = game:GetService("MarketplaceService")
local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local button = script.Parent

local ProductID = 1190752185 --Type DEV id here

local function ProductPurchase(userId, assetId, isPurchased)
     if assetId == ProductID then
          if isPurchased == true then
                print("Player "..userId.." purchased a product which has id "..assetId)
                -- Your script goes here
          end
     end
end

local function PromptProduct()
     MarketplaceService:PromptProductPurchase(player, ProductID)
end

MarketplaceService.PromptProductPurchaseFinished:Connect(ProductPurchase)
button.MouseButton1Click:Connect(PromptProduct)

If work, please make this as a Solution.

it’s not firing the client

local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local button = script.Parent

local ProductID = 1190752185 --Type DEV id here

local function ProductPurchase(userId, assetId, isPurchased)
	if assetId == ProductID then
		if isPurchased == true then
			print("Player "..userId.." purchased a product which has id "..assetId)
			game.ReplicatedStorage.HINTS.Level1:FireClient()
		end
	end
end

local function PromptProduct()
	MarketplaceService:PromptProductPurchase(player, ProductID)
end

MarketplaceService.PromptProductPurchaseFinished:Connect(ProductPurchase)
button.MouseButton1Click:Connect(PromptProduct)```

Does it print out someone purchased?

yes, it just doesn’t fire the server

Then the problem is in your RemoteEvent handles. Can you send the RemoteEvent script?


game.ReplicatedStorage.HINTS.Level1.OnClientEvent:Connect(function()
	Objective.Text = " - Go Upstaris."
end)```
game.ReplicatedStorage.HINTS.Level1.OnServerEvent:Connect(function()
	Objective.Text = " - Go Upstaris."
end)

You’re firing from ClientServer, that mean you had to detect with OnServerEvent, OnClientEvent only fires when you do from ServerClient.