How do I make these pets look forwards?

Hello, I have been working on a pet follower script but I am trying to make the pets face forward instead of facing the HumanoidRotPart.
What do you want to achieve?
I want the pets to face forwards like this:


What is the issue?


What solutions have I tried so far?

wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")

local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4

local fullCircle = 2 * math.pi
local radius = 7

local function getXAndZPositions(angle)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

runService.RenderStepped:Connect(function()
	for i, part in pairs(wands:GetChildren()) do
		local angle = i * (fullCircle / #wands:GetChildren())
		local x, z = getXAndZPositions(angle)

		local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
		local lookAt = hrp.CFrame.LookVector

		part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
	end
end)

Here is my current script that makes the pets face the HumanoidRootPart:

wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")

local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4

local fullCircle = 2 * math.pi
local radius = 7

local function getXAndZPositions(angle)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

runService.RenderStepped:Connect(function()
	for i, part in pairs(wands:GetChildren()) do
		local angle = i * (fullCircle / #wands:GetChildren())
		local x, z = getXAndZPositions(angle)

		local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
		local lookAt = hrp.Position

		part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
	end
end)

Thank you!

Try printing the LookVector of the HumanoidRootPart.

Edit:

you want to do this:

wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")

local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4

local fullCircle = 2 * math.pi
local radius = 7

local function getXAndZPositions(angle)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

runService.RenderStepped:Connect(function()
	for i, part in pairs(wands:GetChildren()) do
		local angle = i * (fullCircle / #wands:GetChildren())
		local x, z = getXAndZPositions(angle)

		local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
		local lookAt = -hrp.CFrame.LookVector --BackVector

		part:SetPrimaryPartCFrame(CFrame.new(position, lookAt))
	end
end)
1 Like

I tried it and this is what happens:

Ohhhhhh okay. The part:SetPrimaryPartCFrame(CFrame.new(position, lookAt)) is the reason. I am going make a system with your code to fix it.

1 Like

I managed to fix it! Here is what I did:

wait(5)
local runService = game:GetService("RunService")
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")

local wands = workspace.PlayerWands:FindFirstChild(character.Name)
local numberOfWands = 4

local fullCircle = 2 * math.pi
local radius = 7

local function getXAndZPositions(angle)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

runService.RenderStepped:Connect(function()
	for i, part in pairs(wands:GetChildren()) do
		local angle = i * (fullCircle / #wands:GetChildren())
		local x, z = getXAndZPositions(angle)

		local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
		local lookAt = hrp.Position

		part:SetPrimaryPartCFrame(CFrame.new(position, lookAt) * CFrame.Angles(0,math.rad(-90),0))
	end
end)

You could just use a weld to do that but isn’t the best for animation.

1 Like

Actually it only works with the first one:

have you fixed your problem? (astgmqtgqwitmwq)

1 Like

Yes I did:

could I see your full code? (char limit)