Problem with RunService

hi so i tried to make egg and pet attach to the player camera but when player hatch egg is with bug.
here is the script:

local RunService = game:GetService("RunService")

game.ReplicatedStorage.ShowOnCam.OnClientEvent:Connect(function(Egg)
	Egg.Parent = workspace.Camera
	RunService.RenderStepped:Connect(function()
		Egg.Position = Vector3.new(3,3,workspace.CurrentCamera.CFrame - 3)
	end)
end)

game.ReplicatedStorage.ShowOnCam.OnClientEvent:Connect(function(Pet)
	Pet.Parent = workspace.Camera
	RunService.RenderStepped:Connect(function()
		Pet.Position = Vector3.new(3,3,workspace.CurrentCamera.CFrame - 3)
	end)
end)

and the error:
image

Do this:

local RunService = game:GetService("RunService")

game.ReplicatedStorage.ShowOnCam.OnClientEvent:Connect(function(Egg)
	Egg.Parent = workspace.Camera
	RunService.RenderStepped:Connect(function()
		Egg.Position = Vector3.new(3,3,workspace.CurrentCamera.CFrame.Position.Z - 3)
	end)
end)

game.ReplicatedStorage.ShowOnCam.OnClientEvent:Connect(function(Pet)
	Pet.Parent = workspace.Camera
	RunService.RenderStepped:Connect(function()
		Pet.Position = Vector3.new(3,3,workspace.CurrentCamera.CFrame.Position.Z - 3)
	end)
end)
1 Like

CFrame is the rotation and position of an object.
So you have to change this to something like:
CurrentCamera.CFrame.Position.Z