Help Fix Shop Script

I am trying to make a store system and nothing happens after I paid the robux.
This script makes the robux thing come up and the other is supposed to give you the orbs. How do i fix this

Also I used Print and found that it does not print when I put it here

MarketPlaceService.ProcessReceipt = function(receiptInfo)
Print("Done")
-- LOCAL SCRIPT INSIDE SIDEUI
---> services
local value = script.Parent.Parent:WaitForChild("ValueUI")
local stat = value:WaitForChild("Stat")

---> variables
local frame = script.Parent.MainFrame
local sframe = script.Parent.SettingsFrame
local iframe = script.Parent.IndexFrame
local openbuttons = frame.Open
local donated = frame.Donate
local gear = frame.Gears
local orbs = frame.Orbs

local exit = script.Parent.MainFrame.Exit
local button = script.Parent.Buttons.A

local obutton = openbuttons.A
local gbutton = openbuttons.B
local dbutton = openbuttons.C

local AD = donated.A
local BD = donated.A
local CD = donated.A
local DD = donated.A
local ED = donated.A
local FD = donated.F

local AO = orbs.A
local BO = orbs.B
local CO = orbs.C
local DO = orbs.D
local EO = orbs.E
local FO = orbs.F

local settingA = script.Parent.Buttons.C
local settingB = script.Parent.SettingsFrame.Exit

local indexA = script.Parent.Buttons.B
local indexB = script.Parent.IndexFrame.Exit

---> main
indexA.MouseButton1Down:Connect(function()
	iframe.Visible = not iframe.Visible
	frame.Visible = false
	sframe.Visible = false
	stat.Visible = false
end)

indexB.MouseButton1Down:Connect(function()
	iframe.Visible = not iframe.Visible
end)

settingA.MouseButton1Down:Connect(function()
	sframe.Visible = not sframe.Visible
	frame.Visible = false
	iframe.Visible = false
	stat.Visible = false
end)

settingB.MouseButton1Down:Connect(function()
	sframe.Visible = not sframe.Visible
end)

button.MouseButton1Down:Connect(function()
	frame.Visible = not frame.Visible
	sframe.Visible = false
	iframe.Visible = false
	stat.Visible = false
end)

obutton.MouseButton1Down:Connect(function()
	orbs.Visible = not orbs.Visible
	gear.Visible = false
	donated.Visible = false
	stat.Visible = false
end)

gbutton.MouseButton1Down:Connect(function()
	gear.Visible = not gear.Visible
	orbs.Visible = false
	donated.Visible = false
	stat.Visible = false
end)

dbutton.MouseButton1Down:Connect(function()
	donated.Visible = not donated.Visible
	gear.Visible = false
	orbs.Visible = false
	stat.Visible = false
end)

exit.MouseButton1Down:Connect(function()
	frame.Visible = not frame.Visible
end)

AD.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456828) -- change to your product id --
end)

BD.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456827)
end)

CD.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456826)
end)

DD.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456825)
end)

ED.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456823)
end)

FD.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456821)
end)

AO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456820)
end)

BO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456819)
end)

CO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456818)
end)

DO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456816)
end)

EO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456814)
end)

FO.MouseButton1Down:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, 1612456813)
end)
-- LOCAL SCRIPT INSIDE STARTERGUI
---> services
local MarketPlaceService = game:GetService("MarketplaceService")

---> main
MarketPlaceService.ProcessReceipt = function(receiptInfo)
	
	--ORBS
	if receiptInfo.ProductId == 1612456820 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.leaderstats.Orbs.Value += 30
		return Enum.ProductPurchaseDecision.PurchaseGranted
	
	else if receiptInfo.ProductId == 1612456819 then
			local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
			player.leaderstats.Orbs.Value += 150
			return Enum.ProductPurchaseDecision.PurchaseGranted
			
		else	if receiptInfo.ProductId == 1612456818 then
				local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
				player.leaderstats.Orbs.Value += 400
				return Enum.ProductPurchaseDecision.PurchaseGranted
				
			else if receiptInfo.ProductId == 1612456816 then
					local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
					player.leaderstats.Orbs.Value += 1000
					return Enum.ProductPurchaseDecision.PurchaseGranted
					
				else if receiptInfo.ProductId == 1612456814 then
						local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
						player.leaderstats.Orbs.Value += 2000
						return Enum.ProductPurchaseDecision.PurchaseGranted
						
					else if receiptInfo.ProductId == 1612456813 then
							local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
							player.leaderstats.Orbs.Value += 5000
							return Enum.ProductPurchaseDecision.PurchaseGranted
							
							--DONATED
						else if receiptInfo.ProductId == 1612456828 then
								local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
								player.leaderstats.Donated.Value += 10
								return Enum.ProductPurchaseDecision.PurchaseGranted
								
							else if receiptInfo.ProductId == 1612456827 then
									local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
									player.leaderstats.Donated.Value += 100
									return Enum.ProductPurchaseDecision.PurchaseGranted
									
								else if receiptInfo.ProductId == 1612456826 then
										local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
										player.leaderstats.Donated.Value += 500
										return Enum.ProductPurchaseDecision.PurchaseGranted
										
									else if receiptInfo.ProductId == 1612456825 then
											local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
											player.leaderstats.Donated.Value += 1000
											return Enum.ProductPurchaseDecision.PurchaseGranted
											
										else if receiptInfo.ProductId == 1612456823 then
												local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
												player.leaderstats.Donated.Value += 10000
												return Enum.ProductPurchaseDecision.PurchaseGranted
												
											else if receiptInfo.ProductId == 1612456821 then
													local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
													player.leaderstats.Donated.Value += 100000
													return Enum.ProductPurchaseDecision.PurchaseGranted
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end
5 Likes

first rule: never trust the client even more when is for robux stuff so i would recommend you to redo the whole script but for server sided and then add it to the client as a part of the Gui,
second i highly recommend to to optimize the gui , it’s not really readable in my POV even more on second script you are checking if the player has bought the product for the first if , but for the elseif it will only check for the first not for the second so only the first one will work.
a way to optimize it/make it easier to be readable is by making tables for example

local products = {
  [productid] = {"ammount to give"}
}
2 Likes

So like this

	
	local products = {
		[1612456820] = {"30"},
		[1612456819] = {"150"},
		[1612456818] = {"400"},
		[1612456816] = {"1000"},
		[1612456814] = {"2000"},
		[1612456813] = {"5000"}
	}

yes, and remake the whole script based on it bet in what i remember you don’t need to use the “number” since it’s not a string you can put the number directly like this

local products = {
[ID] = {Value}
}
1 Like

Like this

local products = {
		[1612456820] = {30},
		[1612456819] = {150},
		[1612456818] = {400},
		[1612456816] = {1000},
		[1612456814] = {2000},
		[1612456813] = {5000}
	}

yes, and then change the script base to work on it, and as i told never trust client for robux stuff, or anything in general since you can’t trust the client, the only thing you can trust the client for is , for animations anything else will have it risk

if you want i can provide you one of my old scripts but is not optimized since i stopped to work with robux stuff inside my games, only for donation but they affect nothing in game, and that script is not really optimized

Pls do---------------------------------------

local MarketplaceService = game:GetService("MarketplaceService")
local rs = game.ReplicatedStorage

local Products = {
	--[[how it works :
	Variable = {
		[ID] = function(receipt, plr)
			what it will do if the player purchase
			return true
		end;
	}
	]]
	Levels = {
		[1] = function(receipt, plr) -- 100 lvl
			plr.leaderstats.Level.Value += 100
			return true
		end;
		[2] = function(receipt, plr) -- 1k lvl
			plr.leaderstats.Level.Value += 1000
			return true
		end;

		Gold = {
			[3] = function(receipt, plr) -- 1k gold
				plr.leaderstats.Gold.Value += 1000
				return true
			end;

			[4] = function(receipt, plr) -- 100k gold
				plr.leaderstats.Gold.Value += 100000
				return true
			end;
		};
	}
}
function MarketplaceService.ProcessReceipt(receiptinfo)
	local playerProductKey = receiptinfo.PlayerId..":"..receiptinfo.PurchaseId
	local plr = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)
	local productInfo = nil

	for category, products in pairs(Products) do
		local handler = products[receiptinfo.ProductId]
		if handler then
			local suc, result = pcall(handler, receiptinfo, plr)
			if not suc or not result then
				warn("Failed to process a product purchase for ProductId:", receiptinfo.ProductId, " Player:", plr)
				return nil
			end

			-- Retrieve product info
			local suc, err = pcall(function()
				productInfo = MarketplaceService:GetProductInfo(receiptinfo.ProductId, Enum.InfoType.Product)
			end)
			break
		end
	end

	if not productInfo then
		warn("Product not found for ProductId:", receiptinfo.ProductId)
		return nil
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

you only have to addapt it for your game

Wait where do I put the IDs----------

check the “how it works”, it tells you literally how it works perfectly