Trouble making an egg hatching system

Hello!

So I am making an Egg Hatching System, and have a script with all the effects and stuff.

NOTE: THIS IS A MODULE SCRIPT

SCRIPT HERE:

local Data = {}
local EggData = {}
local PetIndex = require(script.Parent.Parent.PetModules.PetIndex)
local Eggs = workspace:WaitForChild("Eggs")

function EggData.GetEgg(EggName)
	if not Data[EggName] then
		local Egg = Eggs:FindFirstChild(EggName)
		local Data = PetIndex[EggName]

		if Data then
			local Chance = 0
			for _, pet in pairs(PetIndex[EggName]) do
				Chance += pet.Chance
			end
			EggData[EggName] = {
				Name = EggName,
				Price = Egg:GetAttribute("Price"),
				PetData = Data,
				TotalChance = Chance  
			}
			return EggData[EggName]
		end
	end
end

return EggData

But… I get an error saying this:
image

I have no idea why XD.
TY for any help!

1 Like

Could you show the other script that requires the module and where you run the function?

I think it is because in the function you require, you didn’t think about how you are returning a table.

1 Like

Are you sure the error is referring to the ModuleScript that you showed us? I tested this using your ModuleScript code and did not get the same error.

here is the code requiring the module script:

local Slot = script.Parent.PurchaseMenu.SlotBackground.Slots
local ChosenEgg = script.Parent.CurrentEgg
local Frame = script.Parent.PurchaseMenu
local EggIndex = require(game.ReplicatedStorage.Modules.EggModules.EggIndex)
local EggEffect = require(game.ReplicatedStorage.Modules.EggModules.EggEffect)
local Amount = Frame.AmountBackground.AmountBackground.CurrencyIcon.Cost
local EggName = Frame.NameBackground.Background.TextLabel

local function resetFrame()
	for _, slot in ipairs(Slot:GetChildren()) do
		for _, item in ipairs(slot.PetView:GetChildren()) do
			item:Destroy()
		end		
		slot.Chance.Text = ""
		slot.Rarity.Text = ""
	end
end

ChosenEgg:GetPropertyChangedSignal("Value"):Connect(function()
	if ChosenEgg.Value == "None" then
		resetFrame()
		Frame.Visible = false
	else 
		local Egg = EggIndex.GetEgg(ChosenEgg.Value)
		if Egg then
			resetFrame()
			Amount.Text = Egg.Price
			EggName.Text = Egg.Name
			Frame.Visible = true
			EggEffect.AddPets(Slot, Egg)
		end
	end
end)

Did you pass a string value through the parameters or something else?

It is pretty long but it could help you.

1 Like