Process Receipt not firing?

I’m trying to make a script which serves to process the receipt of a bunch of product purchases, however when I make a test purchase, this function doesn’t fire as it should:

marketPlaceService.ProcessReceipt = function(receiptInfo)
Here's the full script for further context
-- INDEX:

-- PRODUCTS AND TROLLS
-- 1. SKIP STAGE
-- 2. SKIP STAGE ALL
-- 3. UNDO STAGE ALL
-- 4. NUKE SERVER
-- 5. BLIND ALL
-- 6. SLOW ALL
-- 7. SPEED ALL
-- 8. LOW GRAVITY

---------------------------------------------------------------------------------------------------

local marketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local GUI = game:GetService("StarterGui")

marketPlaceService.ProcessReceipt = function(receiptInfo)
	
	local Granted = false
	
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)

	if receiptInfo.ProductId == 1658627474 then
		player.leaderstats.Stage.Value += 1
		wait(1)
		player:LoadCharacter()
		
		Granted = true
	elseif receiptInfo.ProductId == 1659261655 then
		local playername = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		for _, p in pairs(players:GetPlayers()) do
			p.leaderstats.Stage.Value += 1
			wait(1)
			p:LoadCharacter()

			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p.PlayerGui.Default
			TextLabel.Text = p.Name .. " has skipped everyone's stage!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)

			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
		end
		Granted = true
	elseif receiptInfo.ProductId == 1660050340 then
		local playername = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		for _, p in pairs(players:GetPlayers()) do
			if p.Name ~= playername then
				if p.Character.HumanoidRootPart then
					p.leaderstats.Stage.Value -= 1
					wait(1)
					p:LoadCharacter()
				end
			end
			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p.PlayerGui.Default
			TextLabel.Text = p.Name .. " has undone everyone's stages!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)
			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
		end
		Granted = true
	elseif receiptInfo.ProductId == 1658851386 then
		for _, p in pairs(players:GetPlayers()) do
			if p ~= player then
				if p.Character.HumanoidRootPart then
					local explosion = Instance.new("Explosion")
					explosion.Position = CFrame.new(p.HumanoidRootPart.Position)
				end
			end
			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p.PlayerGui.Default
			TextLabel.Text = player.Name .. " has nuked the server!"
			TextLabel.FontFace =  Font.fromName("FredokaOne",Enum.FontWeight.Medium,Enum.FontStyle.Normal)
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)

			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
		end
		Granted = true
	elseif receiptInfo.ProductId == 1660053718 then
		for _, p in pairs(game.Players:GetPlayers()) do
			if p ~= player then
				p.PlayerGui.Default.Blinded.Visible = true
			end

			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p.PlayerGui.Default
			TextLabel.Text = player.Name .. " has blinded everyone for 60s!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)

			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false

			wait(55)

			for _, p in pairs(game.Players:GetPlayers()) do
				p.PlayerGui.Default.Blinded.Visible = false
			end
		end

		GUI.Default.Blinded.Visible = true

		wait(60)

		GUI.Default.Blinded.Visible = false

		Granted = true
	elseif receiptInfo.ProductId == 1660090129 then
		for _, p in pairs(game.Players:GetPlayers()) do
			if p ~= player then
				if p.Character and p.Character:FindFirstChild("HumanoidRootPart") then
					local Humanoid = p.Character.Humanoid
					Humanoid.WalkSpeed = Humanoid.WalkSpeed / 2
					wait(60)
					Humanoid.WalkSpeed = 16
				end
			end
			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
			TextLabel.Text = player.Name .. " has slowed everyone down for 60s!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)

			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
			TextLabel:Destroy()
		end
		Granted = true
	elseif receiptInfo.ProductId == 1660098210 then
		for _, p in pairs(game.Players:GetPlayers()) do
			if p.Character and p.Character:FindFirstChild("HumanoidRootPart") then
				local Humanoid = p.Character.Humanoid
				Humanoid.WalkSpeed = Humanoid.WalkSpeed * 2
				wait(60)
				Humanoid.WalkSpeed = 16
			end
			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
			TextLabel.Text = player.Name .. " has sped everyone up for 60s!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)

			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
			TextLabel:Destroy()
		end
		Granted = true
	elseif receiptInfo.ProductId == 1660096890 then
		game.Workspace.Gravity = 196.2 / 6
		for _, p in pairs(game.Players:GetPlayers()) do
			local TextLabel = Instance.new("TextLabel")
			TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
			TextLabel.Text = player.Name .. " has reduced the gravity for 60s!"
			TextLabel.FontFace = Font.fromName("FredokaOne")
			TextLabel.TextScaled = true
			TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
			TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
			TextLabel.TextColor3 = Color3.new(158, 0, 0)
			TextLabel.Visible = true

			wait(5)

			TextLabel.Visible = false
			TextLabel:Destroy()
		end
		Granted = true
	end
	
	if Granted== true then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

I had this line* of code pasted at the end of every “if” statement however have replaced it with the whole “Granted” idea as I have seen someone say that multiple return lines within one block of code causes numerous bugs

The line of code*
return Enum.ProductPurchaseDecision.PurchaseGranted

What other changes should I make to ensure that the code fires?

1 Like

Solved it: I had multiple scripts using “ProcessReceipt” causing the code to not work, will integrate these scripts into the main code.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.