local EggDebounce:boolean? = false
local ts:TweenService? =game:GetService("TweenService")
local Player:Player? = game.Players.LocalPlayer
local char = workspace:WaitForChild(Player.Name)
local Hum:Humanoid? = char:WaitForChild("Humanoid")
for i,v in pairs(game.Workspace.Eggs:GetChildren()) do
local GrabPets = game.ReplicatedStorage.EggPets[v.Name]
if GrabPets ~= nil then
local ClonedBB = script.EggBuillboard:Clone()
ClonedBB.Parent = script.Parent.Parent.EggBuillboards
ClonedBB.Adornee = v:WaitForChild("BBHolder")
for i,PetModel in pairs(GrabPets:GetChildren()) do
local PetModelClone = PetModel:Clone()
local ClonedTemp = script.PetTemplate:Clone()
ClonedTemp.Parent = ClonedBB.Frame.PetModelHolder
ClonedTemp.Name = PetModel.Name
ClonedTemp.ChanceT.Text = PetModel.Chance.Value.."%"
PetModelClone.Parent = ClonedTemp.PetModelViewer
local NewCam = Instance.new("Camera")
NewCam.Parent = ClonedTemp.PetModelViewer
ClonedTemp.PetModelViewer.CurrentCamera = NewCam
NewCam.CFrame = CFrame.new(PetModelClone.PrimaryPart.Position)
local PetDisConnection = game:GetService("RunService").RenderStepped:Connect(function()
PetModelClone:SetPrimaryPartCFrame(NewCam.CFrame * CFrame.new(0,0,-3) * CFrame.Angles(0,math.rad(time() * 160),0))
end)
--- Buy Func
ClonedBB.Frame.Buy1.MouseButton1Down:Connect(function()
if EggDebounce == false then
EggDebounce = true
local CloneEggMesh = v.EggMesh:Clone()
CloneEggMesh.Parent = workspace.CurrentCamera
local crackdb = false
ClonedBB.Enabled = false
local EggCon = game:GetService("RunService").RenderStepped:Connect(function()
CloneEggMesh:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame * CFrame.new(0,0,-CloneEggMesh.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(tick()* 15)))
if not crackdb then
crackdb = true
script.eggOpen:Play()
wait(0.08)
crackdb = false
end
end)
task.wait(3)
ts:Create(CloneEggMesh.PrimaryPart,TweenInfo.new(1), {Transparency = 1}):Play()
task.wait(0.1)
EggCon:Disconnect()
CloneEggMesh:Destroy()
ClonedBB.Enabled = true
game.ReplicatedStorage.Events.PickRandomPet:FireServer(GrabPets,v.Name)
EggDebounce = false
end
end)
end
end
end
local selectedPet = nil
local function SelectTemp(pet, temp, en)
selectedPet = temp.Name
for i,v in pairs(script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemViewer:GetChildren()) do
if v:IsA("Model") then
v:Destroy()
end
end
for i,e in pairs(script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemViewer:GetChildren()) do
if e:IsA("Camera") then
e:Destroy()
end
end
task.wait()
local PetCloneInfo = game.ReplicatedStorage.EggPets[tostring(en)][tostring(pet)]:Clone()
PetCloneInfo.Parent = script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemViewer
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemName.Text = PetCloneInfo.Name
local newcamInfo = Instance.new("Camera", script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemViewer)
newcamInfo.CFrame = CFrame.new(PetCloneInfo.PrimaryPart.Position)
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.ItemViewer.CurrentCamera = newcamInfo
local Connection = game:GetService("RunService").RenderStepped:Connect(function()
pcall(function()
PetCloneInfo:SetPrimaryPartCFrame(newcamInfo.CFrame * CFrame.new(0,0,-PetCloneInfo.PrimaryPart.Size.Z * 3) * CFrame.Angles(0,math.rad(time() *40),0,0))
end)
end)
end
_G.CreateTemp = function(NewPet, EggName)
local cloendpet = NewPet:Clone()
local clonedTemplate = script.PetModelInventory:Clone()
clonedTemplate.Parent = script.Parent.Parent.Parent.PetInventory.screen.InvFrame.ButtonHolder
cloendpet.Parent = clonedTemplate
local NewCam = Instance.new("Camera", clonedTemplate)
clonedTemplate.CurrentCamera = NewCam
clonedTemplate.Name = cloendpet.Name
print(cloendpet.Name)
NewCam.CFrame = CFrame.new(cloendpet.PrimaryPart.Position)
local EquippedCheck = Instance.new("BoolValue")
EquippedCheck.Name = "EquippedCheck"
EquippedCheck.Parent = clonedTemplate
local Connection = game:GetService("RunService").RenderStepped:Connect(function()
cloendpet:SetPrimaryPartCFrame(NewCam.CFrame * CFrame.new(0,0,-cloendpet.PrimaryPart.Size.Z * 3) * CFrame.Angles(0,math.rad(time() *40),0,0))
end)
clonedTemplate.ClickButton.MouseButton1Down:Connect(function()
SelectTemp(cloendpet, clonedTemplate, EggName)
end)
return clonedTemplate
end
wait(1)
for i,v in pairs(Player:WaitForChild("Pets"):GetChildren()) do
for i,eggdefine in pairs(workspace.Eggs:GetChildren()) do
local Pet = game.ReplicatedStorage.EggPets:FindFirstChild(eggdefine.Name)[v.Name]
local petclone = Pet:Clone()
if v.Name == petclone.Name then
_G.CreateTemp(petclone)
end
end
end
game.ReplicatedStorage.Events.HatchFX.OnClientEvent:Connect(function(PetName,eggname)
script.Parent.Parent.Parent.Details.HatchPopUp.Visible = true
local ClonedPet = PetName:Clone()
ClonedPet.Parent = script.Parent.Parent.Parent.Details.HatchPopUp.PetViewerAfterHatch
local newcam = Instance.new("Camera", script.Parent.Parent.Parent.Details.HatchPopUp.PetViewerAfterHatch)
script.Parent.Parent.Parent.Details.HatchPopUp.PetViewerAfterHatch.CurrentCamera = newcam
newcam.CFrame = CFrame.new(ClonedPet.PrimaryPart.Position)
script.Parent.Parent.Parent.Details.HatchPopUp.PetViewerAfterHatch.PetNameText.Text = ClonedPet.Name.."["..ClonedPet.Chance.Value.."%]".."!"
script.Parent.Parent.Parent.Details.HatchPopUp.PetViewerAfterHatch.PetNameText.PetNameTextBg.Text = ClonedPet.Name.."["..ClonedPet.Chance.Value.."%]".."!"
script.EggOpenSFXPet:Play()
local Connection = game:GetService("RunService").RenderStepped:Connect(function()
ClonedPet:SetPrimaryPartCFrame(newcam.CFrame * CFrame.new(0,0,-ClonedPet.PrimaryPart.Size.Z * 2.4) * CFrame.Angles(0,math.rad(time() * 90),0,0))
end)
wait(3)
_G.CreateTemp(PetName,eggname)
script.Parent.Parent.Parent.Details.HatchPopUp.Visible = false
Connection:Disconnect()
wait(1)
ClonedPet:Destroy()
end)
local db = false
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.equip.MouseButton1Down:Connect(function()
if db == false then
db = true
if selectedPet ~= nil and selectedPet.EquippedCheck.Value == false and selectedPet.EquippedCheck.Value ~= nil then
local Result = game.ReplicatedStorage.Events.PetEquip:InvokeServer(selectedPet)
if Result == true then
selectedPet.EquippedCheck.Value = true
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.equip.Text = "Equipped"
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.equip.BackgroundColor3 = Color3.fromRGB(24, 255, 24)
end
elseif selectedPet.EquippedCheck.Value == true and selectedPet.EquippedCheck.Value ~= nil then
selectedPet.EquippedCheck.Value = false
game.ReplicatedStorage.Events.UnequipPet:InvokeServer(selectedPet)
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.equip.Text = "Equip"
script.Parent.Parent.Parent.PetInventory.screen.InvFrame.bg.Info.equip.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
end
else
print("Error")
end
wait(2)
db = false
end)
i’m having a problem with my pet system i am saving data of pets and trying to create a new template in the pet inventory ui, it created it but when i press it it returns an error saying nil is not a valid memeber of this folder here:
i am not sure if i am doing something wrong if someone could look through the create template function and the select template one i would appreciate it. it is when i am creating creating the new template for the pet and getting it from the folder. since this only happens when i load in and the templates are there it will not me select it.