I need help with an egg hatching system, everything else works except this. The egg doesn’t show up in front of the camera, despite the fact that the egg is a child of the camera. Please help.
Script:
function EggModule.Hatch_Egg(eggName, petName)
local eggMesh = eggs[eggName]["Egg_Model"]
if eggMesh ~= nil then
local clonedMesh = eggMesh:Clone()
clonedMesh.Parent = camera
for _, obj in next, clonedMesh:GetDescendants() do
if obj:IsA("BasePart") or obj:IsA("UnionOperation") then
obj.CanCollide = false
obj.CastShadow = false
elseif obj:IsA("ProximityPrompt") then
obj:Destroy()
end
end
egg_Connection = runService.RenderStepped:Connect(function()
local cf = CFrame.new(0,0,clonedMesh.PrimaryPart.Size.Z*2)* CFrame.Angles(0,0,math.sin(time() * eggShakeSpeed)*eggShakeSize)
clonedMesh:SetPrimaryPartCFrame(camera.CFrame * cf)
end)
wait(eggShakeDuration)
for _, obj in next, clonedMesh:GetDescendants() do
if obj:IsA("BasePart") or obj:IsA("UnionOperation") then
tweenService:Create(obj, TweenInfo.new(eggFadeDuration),{Transparency = 1}):Play()
end
end
wait(eggFadeDuration*1.08)
egg_Connection:Disconnect()
clonedMesh:Destroy()
return petName
end
end
local runService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local clonedMesh = script.Parent.ViewportFrame:WaitForChild("Model")
local eggShakeSpeed = 5 -- random stuff
local eggShakeSize = 2-- random stuff
egg_Connection = runService.RenderStepped:Connect(function()
local cf = CFrame.new(0,0,-7)* CFrame.Angles(0,0,math.sin(time() * eggShakeSpeed)*eggShakeSize)
clonedMesh:SetPrimaryPartCFrame(cf)
end)
CFrame.new(0,0,-7) this puts the part bit far from the camera
heres a .rbxm file to test it out stuff.rbxm (5.7 KB)
edit: if this solves the problem mark this as solved