Pet/Egg system with multiple developer products in a Module script

I got a Pet system and I wanted to ask how can I make multiple Robux eggs in a module script?
Thats the module script.

local Eggs = {
	Robux = {
		Cost = 99,
		Currency = "R$",
		ProductID = 1528325390,
		Pets = {
			[1] = {Name = "", Type = "Normal", Rarity = 45000, Secret = false},
			[2] = {Name = "", Type = "Normal", Rarity = 26000, Secret = false},
			[3] = {Name = "", Type = "Normal", Rarity = 15000, Secret = false},
			[4] = {Name = "", Type = "Normal", Rarity = 9000, Secret = false},
			[5] = {Name = "", Type = "Normal", Rarity = 4000, Secret = false},
			[6] = {Name = "", Type = "Normal", Rarity = 995, Secret = false},


		}
	},

	Robux2 = {
		Cost = 399,
		Currency = "R$",
		ProductID = 1528493634,
		Pets = {
			[1] = {Name = "", Type = "Normal", Rarity = 45000, Secret = false},
			[2] = {Name = "", Type = "Normal", Rarity = 26000, Secret = false},
			[3] = {Name = "", Type = "Normal", Rarity = 15000, Secret = false},
			[4] = {Name = "", Type = "Normal", Rarity = 9000, Secret = false},
			[5] = {Name = "", Type = "Normal", Rarity = 4000, Secret = false},
			[6] = {Name = "", Type = "Normal", Rarity = 995, Secret = false},

		}
	},

	Robux3 = {
		Cost = 999,
		Currency = "R$",
		ProductID = 1528483458,
		Pets = {
			[1] = {Name = "", Type = "Normal", Rarity = 45000, Secret = false},
			[2] = {Name = "", Type = "Normal", Rarity = 26000, Secret = false},
			[3] = {Name = "", Type = "Normal", Rarity = 15000, Secret = false},

		}
	},


}

return Eggs

And thats the server script for the receipt:

for i,v in pairs(Eggs) do
	local ProductID = v["ProductID"]
	if ProductID ~= nil then
		MS.ProcessReceipt = function(ReceiptInfo)
			local Player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
			if ReceiptInfo.ProductId == ProductID then
				spawn(function()
					local Result = singleEgg(Player, i)
					RS.RemoteEvents.EggOpened:InvokeClient(Player, Eggs[i], Result)
				end)
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end
	end
end

Can’t you just copy and paste the Robux = {–code} part in the module then rename it accordingly, or am I missing something?

I dont get what you mean, the robux code is in the module

It only works for 1 egg and not all 3 eggs

Oh I see, well the loop you have in the main script loops through the devproducts and you’re not looping through the eggs, depending on what the remote function does you can write another loop for j ,pet for example to go through every pet in the pets table, hope this helps.

good script, but a little heads up, you shouldn’t be using InvokeClient, there’s a thing about it.
Such as:

  • If the client throws an error, the server will throw the error too.

  • If the client disconnects while it’s being invoked, the InvokeClient() call will error.

  • If the client never returns a value, the server will hang forever.

Seeing as how you aren’t using the returned value of the RemoteFunction, you should just swap it to a RemoteEvent.