How would I make a part face a player only by the X axis?

Hello,

I’m trying to make a part face the player only by the X axis. But this script faces the part at the player by X, Y, and Z. How can I make it face the player only by the X axis?

Script:

local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local PlayerHead = Character:WaitForChild("Head")
local Part = script.Parent

while wait() do
	TweenService:Create(Part, TweenInfo.new(0), {CFrame = CFrame.new(Part.CFrame.Position, PlayerHead.CFrame.Position)}):Play()
end
5 Likes
local TweenService = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local Part = script.Parent

while true do task.wait()
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

    TweenService:Create(Part, TweenInfo.new(0), {
        CFrame = CFrame.lookAt(Part.Position, Vector3.new(
            HumanoidRootPart.Position.X,
            Part.Position.Y,
            HumanoidRootPart.Position.Z
        ))
    }):Play()
end

try this

EDIT: should work if you reset your character now

2 Likes

Thank you, this worked exactly how I wanted it to work!

1 Like

I have another question, How would I change the X orientation to 90 with a different script?

1 Like

Orientation works for me…

Maybe:

Ori = Part.Orientation
Part.Orientation = Vector3.new (Ori.x + 90, Ori.y, Ori.z)

When using both scripts I mean, if I set the orientation to 90 it will automatically reset from the other script.