How to make the orientation of a MeshPart the same as the HumanoidRootPart's?

Hey Devs! I’m having a problem where when I set the Orientation property of a MeshPart through a script, nothing happens! I have a tool where you can build walls by clicking, although when I set the orientation of the MeshPart that I cloned from ReplicatedStorage, nothing happens. The wall clones fine but the orientation does not change at all. When you click with the tool equipped, I want a wall to appear right in front of the humanoid’s root part. I have that down but the orientation wont be set differently. The orientation property is the same value for every MeshPart I clone, even when I set it differently!

game.ReplicatedStorage:WaitForChild(‘Clone’).OnServerEvent:Connect(function(player,hit)

print(‘Here’)

local Mesh = game.ReplicatedStorage:WaitForChild(‘MeshPart’):Clone()

Mesh.Name = ‘Wall’

Mesh.Parent = game.Workspace

Mesh.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-35)

–Mesh.Position = Vector3.new(1,1,0)

print(player.Character.HumanoidRootPart.Orientation)

Mesh.Orientation = Vector3.new(player.Character.HumanoidRootPart.Orientation)

wait(0.5)

Mesh.Anchored = true

end)

The Mesh will already match the Orientation of the HumanoidRootPart thanks to this line:

Mesh.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-35)

Here’s a problematic line you should know about (and just delete):

Mesh.Orientation = Vector3.new(player.Character.HumanoidRootPart.Orientation)

HumanoidRootPart.Orientation is a Vector3. Your code is doing Vector3.new(aVector3), which isn’t a valid way to construct a Vector3

If you needed that line, and you don’t, the correct way to write it would be like this

Mesh.Orientation = player.Character.HumanoidRootPart.Orientation

Unrelated to this Orientation business, another problem with your code is that it never makes sure player.Character and player.Character.HumanoidRootPart actually exist. You’ll need to do that before using them.

1 Like