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
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)