local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local camera = workspace.CurrentCamera
local function Hatch(egg)
local TweenService = game:GetService("TweenService")
local start = egg.C1
local goal = egg.C2
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = start.CFrame
task.wait(.1)
TweenService:Create(camera, TweenInfo.new(0.25), { CFrame = goal.CFrame }):Play()
wait(2.5)
local folder = game.ReplicatedStorage.Pets:FindFirstChild(egg:GetAttribute("Sort")):GetChildren()
local chosen = folder[math.random(1, #folder)]:Clone()
chosen.Parent = workspace
for _, v in pairs(egg.Egg:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
v.Transparency = 1
end
end
if chosen:IsA("Model") then
for _, v in pairs(chosen:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
chosen:SetPrimaryPartCFrame(egg.PetPosition.CFrame)
elseif chosen:IsA("BasePart") then
chosen.Anchored = true
chosen.CFrame = egg.PetPosition.CFrame
end
wait(2)
chosen:Destroy()
camera.CameraType = Enum.CameraType.Custom
for _, v in pairs(egg.Egg:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0
end
end
end
local Debounce = false
local CollectionService = game:GetService("CollectionService")
for _, egg in pairs(CollectionService:GetTagged("Eggs")) do
playerGui
:WaitForChild("BillboardGui", 10)
:WaitForChild("Frame")
:WaitForChild("TextButton").MouseButton1Click
:Connect(function()
if not Debounce then
Debounce = true
local Animation = egg.Egg.Humanoid:LoadAnimation(egg.Egg.Animation)
Animation:Play()
task.wait(Animation.Length - 0.05)
Hatch(egg)
Debounce = false
end
end)
end
When I hatch the egg the first time it set the camera accordingly. But the 2nd time I try to hatch the egg it doesn’t set the CFrame.
I’m talking about this line:
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = start.CFrame