How do I stop my LookVector from rotating up/down?

In this script I am trying to spawn a part on my MousePosition. this part then rotates with the LookVector of my HumanoidRootPart (HRP), which makes the wall rotate away from your character on the place you clicked

Visual Example

The issue im facing is that the part is rotating on the y axis (Up and down, creates more of a slope then a wall). Im trying to make it flat and not on an angle. My theory is that since my HRP is above the ground, the angle is meant to “compensate” for it. But I have no idea how to fix it.

*This is done in a local script

local tool = script.Parent.Parent
local player = game:GetService("Players").LocalPlayer
local RSF = game:GetService("ReplicatedStorage")
local mouse = player:GetMouse()
local HRP = player.Character.HumanoidRootPart

local function WallSpawn()
	local MousePosition = mouse.hit
	local MousePosY = MousePosition.Y
	local MousePosX = MousePosition.X
	local MousePosZ = MousePosition.Z
	local wall = RSF.Wall:Clone()
	
	wall.Parent = workspace
	wall.CFrame = CFrame.new(MousePosX,MousePosY,MousePosZ)
	local lv =  HRP.CFrame.LookVector
	
	wall.CFrame = MousePosition + lv
	task.wait(10)
	
	for i = 1,10 do
		wall.Transparency += 0.2
		wait(0.33)
		wall:Destroy()
	end
end


tool.Activated:Connect(function()
	WallSpawn()
end)

Thank you for your help

As it is a vector, you can probably just mess around with the X Y and Z orientation things to see which affects the up and down direction.
Then, you can times that particular angle by 0
e.g.

local lv =  HRP.CFrame.LookVector * Vector.new(1, 1, 0) -- Removes the Z component
1 Like

Can’t you read the HRP.CFrame.LookVector’s X,Y and Z rotations and only use the Y value for the Orientation of the wall?

Also,

	for i = 1,10 do
		wall.Transparency += 0.2
		wait(0.33)
		wall:Destroy()
	end

Shouldn’t wall.Destroy() be after the end of the loop?

1 Like