Pet Follow System!

How would i make the pets face to the player? Help will be appreciated!

FullCode:

local function posPets(playerCharacter, playerPetFolder)
	for i, v in playerPetFolder:GetChildren() do
		local radius = minimum_radius + #playerPetFolder:GetChildren()
		local angle = i * (circle / #playerPetFolder:GetChildren())
		local y_offset = 1
		local x = math.cos(angle) * radius
		local z = math.sin(angle) * radius
		
		local walk_up_down_sine = math.max(math.sin((time() + 0.5) * 10) / 2, -0.1)
		local walk_front_cos = math.cos((time() + 0.5) * 10) / 7
		local hover_sine = math.sin((time() + 0.5) * 5) / 8
		local hover_sine_idle = math.sin((time() + 0.5)) / 8
		
		local TargetCFrame = playerCharacter.HumanoidRootPart.CFrame * CFrame.new(x, y_offset, z)
		local pet_cframe = v:GetPivot():Lerp(TargetCFrame, 0.1)
		
		if playerCharacter.Humanoid.MoveDirection.Magnitude > 0 then
			if v:FindFirstChild("Flying") then
				pet_cframe *= CFrame.new(0, walk_up_down_sine, 0) * CFrame.Angles(walk_front_cos, 0, 0)
			else
				pet_cframe *= CFrame.new(0, 0.2 + hover_sine, 0)
			end
		end
		
		v:PivotTo(pet_cframe)
	end
end
2 Likes

Guessing

pet.CFrame = CFrame.new(pet.Position, humrootpart.Position)
2 Likes

I know its i needed to use CFrame Lookat but it doesn’t work for me.

1 Like

How about this.

local TargetCFrame = playerCharacter.HumanoidRootPart.CFrame * CFrame.new(x, y_offset, z) * CFrame.lookAt(playerCharacter.HumanoidRootPart.Position, v.Position)
1 Like