task.wait(.45)
local Settings = {
AppearDistance = 18,
PetModelDisplayFOV = 10,
PetModelDisplayDistance = 2,
PetModelDisplayRotationSpeed = 1.2,
UIStrokeHoverThickness = 2,
HatchLength = 6,
EggHatchDistance = 2.5,
DefaultHatchSpeed = 12,
ShakeSpeed = 12,
PetVisibilityLength = 4,
EggHatchShakeMaxReach = 3.5,
FrameHoverColor = Color3.fromRGB(95, 92, 144),
FrameClickColor = Color3.fromRGB(84, 255, 178)
}
local RarityColors = {
Common = Color3.fromRGB(185, 184, 222),
Un_Common = Color3.fromRGB(83, 255, 184),
Rare = Color3.fromRGB(255, 116, 118),
}
local FrameClicked = false
local Hatchable = false
local HatchingEgg = false
local Connection = nil
local User = game:GetService("Players").LocalPlayer
local Camera = game.Workspace.Camera
local CurrentCamera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local EggsFolder = game.Workspace.EggsFolder
local EggPetsFolder = ReplicatedStorage.EggPets
local Module3D = require(ReplicatedStorage:WaitForChild("Module3D"))
local function HatchPet(PetName, Egg)
local Pet = EggPetsFolder:FindFirstChild(Egg.Name):FindFirstChild(PetName):Clone()
HatchingEgg = true
local Clone = Egg:FindFirstChild("MainEgg"):Clone()
Clone.Parent = Camera
task.spawn(function()
for _, Object in pairs(Clone:GetChildren()) do
if Object:IsA("BasePart") then
Object.Anchored = true
Object.CanCollide = false
end
end
end)
task.spawn(function()
Settings.ShakeSpeed = Settings.DefaultHatchSpeed
end)
task.spawn(function()
for _, Object in pairs(script.Parent.Displays:GetChildren()) do
if Object:IsA("BillboardGui") then
Object.Parent = ReplicatedStorage.Storage
end
end
end)
--local Speed = 12
--task.spawn(function()
-- Connection = RunService.RenderStepped:Connect(function()
-- Clone:SetPrimaryPartCFrame(CurrentCamera.CFrame * CFrame.new(0,0,-Clone.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * Speed)/2.2))
-- print(Speed)
-- task.wait(1.3)
-- if Speed < 20 then
-- Speed += .05
-- else
-- Speed = 12
-- end
-- end)
--end)
task.spawn(function()
local Speed = 12
Connection = RunService.RenderStepped:Connect(function()
Clone:SetPrimaryPartCFrame(CurrentCamera.CFrame * CFrame.new(0,0, -Clone.PrimaryPart.Size.Z * 2) * CFrame.Angles(0,0,math.sin(time() * Speed)/2.2))
print(Speed)
task.wait(1.3)
if Speed < 20 then
Speed += .05
end
end)
end)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Clone.PrimaryPart.CameraDis.CFrame
task.wait(.8)
TweenService:Create(Clone.PrimaryPart,TweenInfo.new(.8,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(2.25, 2,2.25)}):Play()
task.spawn(function()
task.wait(.2)
if Pet.Values.Rarity.Value == "Common" then
TweenService:Create(Clone.PrimaryPart.Crack,TweenInfo.new(.9),{Transparency = 0, Color3 = RarityColors.Common}):Play()
task.wait(.8)
TweenService:Create(Clone.PrimaryPart.Crack2,TweenInfo.new(.6),{Transparency = 0, Color3 = RarityColors.Common}):Play()
end
if Pet.Values.Rarity.Value == "Un-Common" then
TweenService:Create(Clone.PrimaryPart.Crack,TweenInfo.new(.9),{Transparency = 0, Color3 = RarityColors.Un_Common}):Play()
task.wait(.8)
TweenService:Create(Clone.PrimaryPart.Crack2,TweenInfo.new(.6),{Transparency = 0, Color3 = RarityColors.Un_Common}):Play()
end
if Pet.Values.Rarity.Value == "Rare" then
TweenService:Create(Clone.PrimaryPart.Crack,TweenInfo.new(.9),{Transparency = 0, Color3 = RarityColors.Rare}):Play()
task.wait(.8)
TweenService:Create(Clone.PrimaryPart.Crack2,TweenInfo.new(.6),{Transparency = 0, Color3 = RarityColors.Rare}):Play()
end
end)
task.spawn(function()
task.wait((Settings.HatchLength / 2) - .65)
TweenService:Create(Clone.PrimaryPart,TweenInfo.new(.45,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(50, 50, 50)}):Play()
end)
task.spawn(function()
task.wait(2.8)
TweenService:Create(Clone.PrimaryPart,TweenInfo.new(.45,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(0, 0, 0)}):Play()
TweenService:Create(Clone.PrimaryPart.Crack,TweenInfo.new(.45,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{Transparency = 1}):Play()
task.spawn(function()
task.wait(.2)
TweenService:Create(Clone.PrimaryPart,TweenInfo.new(.45,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(360)}):Play()
end)
task.wait(.15)
task.spawn(function()
for _, Object in pairs(Clone:GetChildren()) do
if Object:IsA("BasePart") then
TweenService:Create(Object,TweenInfo.new(.45),{Transparency = 1}):Play()
end
end
Speed = 12
end)
end)
task.wait(Settings.HatchLength)
task.wait(.25)
Connection:Disconnect()
task.wait(.2)
Clone:Destroy()
script.Parent.PetObtainedDisplay.Visible = true
task.spawn(function()
local PetModel = Module3D:Attach3D(script.Parent.PetObtainedDisplay,Pet:Clone())
PetModel.Visible = true
PetModel:SetDepthMultiplier(Settings.PetModelDisplayDistance)
PetModel.Camera.FieldOfView = Settings.PetModelDisplayFOV
RunService.RenderStepped:Connect(function()
PetModel:SetCFrame(CFrame.Angles(0,tick() * Settings.PetModelDisplayRotationSpeed % (math.pi * 2),0) * CFrame.Angles(math.rad(-9),0,0))
end)
end)
task.wait(Settings.PetVisibilityLength)
TweenService:Create(script.Parent.PetObtainedDisplay:FindFirstChildWhichIsA("ViewportFrame"),TweenInfo.new(.45),{ImageTransparency = 1}):Play()
task.wait(.5)
task.spawn(function()
for _, Object in pairs(script.Parent.PetObtainedDisplay:GetDescendants()) do
if Object:IsA("ViewportFrame") then
Object:Destroy()
end
end
end)
script.Parent.PetObtainedDisplay.Visible = false
task.wait(.1)
Camera.CameraType = Enum.CameraType.Custom
HatchingEgg = false
task.spawn(function()
for _, Object in pairs(ReplicatedStorage.Storage:GetChildren()) do
if Object:IsA("BillboardGui") then
Object.Parent = script.Parent.Displays
end
end
end)
end
local function EHatchFunction()
if User.Character ~= nil and HatchingEgg == false then
local PartPosition = User.Character:FindFirstChild("HumanoidRootPart").Position
local ClosestModel
for _, Egg in pairs(EggsFolder:GetChildren()) do
if ClosestModel == nil then
ClosestModel = Egg
else
if (PartPosition - Egg.PrimaryPart.Position).Magnitude < (ClosestModel.PrimaryPart.Position - PartPosition).Magnitude then
ClosestModel = Egg
end
end
end
if User:DistanceFromCharacter(ClosestModel:WaitForChild("MainEgg").PrimaryPart.Position) < Settings.AppearDistance then
Hatchable = true
else
Hatchable = false
end
if Hatchable == true then
local HatchEventOutcome = ReplicatedStorage.Hatch:InvokeServer(ClosestModel)
if HatchEventOutcome ~= nil then
HatchPet(HatchEventOutcome, ClosestModel)
end
end
end
end
local function Tween(Target,Bool)
if Bool then
Target.Enabled = true
local EggPetIndex = Target.EggPetIndex
task.spawn(function()
TweenService:Create(EggPetIndex,TweenInfo.new(.2),{Position = UDim2.new(.5,0,0.376,0),Size = UDim2.new(1,0,0.751,0),BackgroundTransparency = 0}):Play()
for _, Object in pairs(EggPetIndex.IndexHolder:GetDescendants()) do
if Object:IsA("Frame") and Object.Name ~= "PetDisplay" then
task.spawn(function()
task.wait(.1)
if Object:FindFirstChild("Chances") then
Object:FindFirstChild("Chances").Visible = true
task.spawn(function()
local ChancesText = Object:FindFirstChild("Chances")
for _i, Pet in pairs(game.ReplicatedStorage:GetDescendants()) do
if Pet:IsA("Model") and Pet.Name == Object.Name then
local Rarity = Pet:FindFirstChild("Values").Rarity
if Rarity.Value == "Common" then
ChancesText.TextColor3 = RarityColors.Common
elseif Rarity.Value == "Un-Common" then
ChancesText.TextColor3 = RarityColors.Un_Common
elseif Rarity.Value == "Rare" then
ChancesText.TextColor3 = RarityColors.Rare
end
end
end
end)
end
end)
end
end
end)
task.spawn(function()
for _, Object in pairs(EggPetIndex.IndexHolder:GetChildren()) do
if Object:IsA("Frame") then
TweenService:Create(Object,TweenInfo.new(.2),{BackgroundTransparency = 0}):Play()
Object.MouseEnter:Connect(function()
TweenService:Create(Object,TweenInfo.new(.2),{BackgroundColor3 = Settings.FrameHoverColor}):Play()
TweenService:Create(Object.UIStroke,TweenInfo.new(.2),{Thickness = Settings.UIStrokeHoverThickness}):Play()
end)
Object.MouseLeave:Connect(function()
TweenService:Create(Object,TweenInfo.new(.2),{BackgroundColor3 = Color3.fromRGB(68, 66, 103)}):Play()
TweenService:Create(Object.UIStroke,TweenInfo.new(.2),{Thickness = 0}):Play()
end)
Object.InputBegan:Connect(function(InputObject)
if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
if not FrameClicked then
FrameClicked = true
TweenService:Create(Object.UIStroke,TweenInfo.new(.25),{Thickness = Settings.UIStrokeHoverThickness}):Play()
script.Parent.InforText.Visible = true
script.Parent.InforText.Rarity.Visible = true
if User:WaitForChild("Pets"):FindFirstChild(Object.Name) then
script.Parent.InforText.Text = "Owned"
else
script.Parent.InforText.Text = "Not Owned"
end
task.spawn(function()
for _i, Pet in pairs(game.ReplicatedStorage:GetDescendants()) do
if Pet:IsA("Model") and Pet.Name == Object.Name then
local Rarity = Pet:FindFirstChild("Values").Rarity
script.Parent.InforText.Rarity.Text = Rarity.Value
if Rarity.Value == "Common" then
script.Parent.InforText.Rarity.TextColor3 = RarityColors.Common
elseif Rarity.Value == "Un-Common" then
script.Parent.InforText.Rarity.TextColor3 = RarityColors.Un_Common
elseif Rarity.Value == "Rare" then
script.Parent.InforText.Rarity.TextColor3 = RarityColors.Rare
end
end
end
end)
task.wait(1)
TweenService:Create(Object.UIStroke,TweenInfo.new(.25),{Thickness = 0}):Play()
script.Parent.InforText.Visible = false
script.Parent.InforText.Rarity.Visible = false
task.wait(.2)
FrameClicked = false
end
end
end)
end
end
end)
task.spawn(function()
for _, Object in pairs(EggPetIndex.IndexHolder:GetChildren()) do
if Object:IsA("ViewportFrame") then
task.wait(.1)
Object.Visible = true
end
end
end)
local Interactions = EggPetIndex.Interactions
task.spawn(function()
for _, Button in pairs(Interactions:GetChildren()) do
if Button:IsA("TextButton") then
TweenService:Create(Button,TweenInfo.new(.3),{BackgroundTransparency = 0, TextTransparency = 0}):Play()
Button.MouseEnter:Connect(function()
TweenService:Create(Button.UIStroke,TweenInfo.new(.2),{Thickness = Settings.UIStrokeHoverThickness + .5}):Play()
TweenService:Create(Button,TweenInfo.new(.2),{BackgroundColor3 = Color3.fromRGB(55,53,83)}):Play()
end)
Button.MouseLeave:Connect(function()
TweenService:Create(Button.UIStroke,TweenInfo.new(.2),{Thickness = 0}):Play()
TweenService:Create(Button,TweenInfo.new(.2),{BackgroundColor3 = Color3.fromRGB(30,29,45)}):Play()
end)
-- I'll make it so when the player clicks the button, it shrinks and then gets to normal size and make it green and then normal color after .3 seconds
end
end
end)
else
local EggPetIndex = Target.EggPetIndex
task.spawn(function()
TweenService:Create(EggPetIndex,TweenInfo.new(.2),{Position = UDim2.new(.5,0,0.45,0),Size = UDim2.new(.9,0,0.7,0),BackgroundTransparency = 1}):Play()
for _, Object in pairs(EggPetIndex.IndexHolder:GetDescendants()) do
if Object:IsA("Frame") and Object.Name ~= "PetDisplay" then
if Object:FindFirstChild("UIStroke") then
Object.UIStroke.Thickness = 0
end
task.spawn(function()
task.wait(.1)
if Object:FindFirstChild("Chances") then
Object:FindFirstChild("Chances").Visible = false
Object:FindFirstChild("Chances").UIStroke.Thickness = 0
end
end)
end
end
end)
task.spawn(function()
for _, Object in pairs(EggPetIndex.IndexHolder:GetChildren()) do
if Object:IsA("Frame") then
TweenService:Create(Object,TweenInfo.new(.3),{BackgroundTransparency = 1}):Play()
end
end
end)
task.spawn(function()
for _, Object in pairs(EggPetIndex.IndexHolder:GetChildren()) do
if Object:IsA("ViewportFrame") then
Object.Visible = false
end
end
end)
task.spawn(function()
local Interactions = EggPetIndex.Interactions
for _, Button in pairs(Interactions:GetChildren()) do
if Button:IsA("TextButton") then
TweenService:Create(Button,TweenInfo.new(.2),{BackgroundTransparency = 1, TextTransparency = 1}):Play()
Button.UIStroke.Thickness = 0
TweenService:Create(Button,TweenInfo.new(.2),{BackgroundColor3 = Color3.fromRGB(30,29,45)}):Play()
end
end
end)
task.wait(.25)
Target.Enabled = false
end
end
for _, Egg in pairs(EggsFolder:GetChildren()) do
local EggPets = EggPetsFolder:FindFirstChild(Egg.Name)
if EggPets ~= nil then
local EggDisplay = script.EggDisplay:Clone()
local EggPetIndex = EggDisplay.EggPetIndex
local IndexHolder = EggPetIndex.IndexHolder
local PetFrame = IndexHolder.PetFrame
local PetDisplay = PetFrame.PetDisplay
EggDisplay.Parent = script.Parent.Displays
EggDisplay.Enabled = true
EggDisplay.Adornee = Egg:WaitForChild("MainEgg").PrimaryPart
EggDisplay.Name = Egg.Name
local PetsTable = {}
for _i, Pet in pairs(EggPets:GetChildren()) do
table.insert(PetsTable,Pet:WaitForChild("Values").Chance.Value)
end
table.sort(PetsTable)
for Effect = 1, math.floor(#PetsTable/2) do
local Value = #PetsTable - Effect + 1
PetsTable[Effect], PetsTable[Value] = PetsTable[Value], PetsTable[Effect]
end
for _i, Chance in pairs(PetsTable) do
for _a, Pet in pairs(EggPets:GetChildren()) do
if Pet:WaitForChild("Values").Chance.Value == Chance then
local NewPetFrame = PetFrame:Clone()
NewPetFrame.Parent = IndexHolder
NewPetFrame.Visible = true
NewPetFrame.Name = Pet.Name
NewPetFrame.Chances.Text = tostring(Pet:WaitForChild("Values").Chance.Value).."%"
local PetModel = Module3D:Attach3D(NewPetFrame.PetDisplay,Pet:Clone())
PetModel.Visible = true
PetModel:SetDepthMultiplier(Settings.PetModelDisplayDistance)
PetModel.Camera.FieldOfView = Settings.PetModelDisplayFOV
RunService.RenderStepped:Connect(function()
PetModel:SetCFrame(CFrame.Angles(0,tick() * Settings.PetModelDisplayRotationSpeed % (math.pi * 2),0) * CFrame.Angles(math.rad(-9),0,0))
end)
break
else
continue
end
end
end
RunService.RenderStepped:Connect(function()
if User:DistanceFromCharacter(Egg:WaitForChild("MainEgg").PrimaryPart.Position) < Settings.AppearDistance then
Tween(EggDisplay,true)
else
Tween(EggDisplay,false)
end
end)
end
end
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
EHatchFunction()
end
end)
Can you replace your code with that and tell me if the error still exists? (The issue you’re having)