CFrame causing orientation to not change

game:GetService("RunService").RenderStepped:connect(function()
	if Player:GetAttribute("Buildmode") == true then
		local mouseRay = mouse.UnitRay
		local rayCastParams = RaycastParams.new()
		rayCastParams.FilterDescendantsInstances = {block,Player.Character}
		rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist

		local raycastResult = game.Workspace:Raycast(mouseRay.Origin,mouseRay.Direction.unit * 500,rayCastParams)

		if raycastResult then
			local target = raycastResult.Instance:GetFullName()
			local pos = raycastResult.Position
			local norm = raycastResult.Normal
			local block = game.Workspace.Ignore:WaitForChild("SelectBox")
			local endPos = (pos + (norm * (block.Size*.5)))
			local endPos = Vector3.new(math.floor(endPos.X + 0.5) + block.Size.X % 2 / 2 , math.round(endPos.Y), math.floor(endPos.Z + 0.5) + block.Size.Z % 2 / 2)
			block.CFrame = CFrame.new(endPos)
			
			if game.Workspace.Ignore:WaitForChild("SelectBox"):FindFirstChildWhichIsA("Model") then
				game.Workspace.Ignore:WaitForChild("SelectBox"):FindFirstChildWhichIsA("Model").PrimaryPart.CFrame = CFrame.new(endPos) 
			

			end
		end
	end
end)

This script sets the part’s position with CFrame when renderstepped happens, but for some reason the orientation can never be changed when the script is running.

Im assuming endPosition is suppose to be where its looking

CFrame.new(Position,LookAt) 

Look at would be the position its Looking at
I’m going to assume but please correct me if I’m wrong…

Is this what you were going for

CFrame.new(block.Position,endPos)

no, endPosition is the actual position the block should be, I still haven’t found way to change the orientation through CFrame,.

You would just add another position as the second parameter of Cframe.new to set where u want the part to face/Orientation or Use Cframe.Angles

Yes, but i want it to face a specific direction+

And that specific direction being? Can you explain where it would be or give an example?

vector3.new(Block.Orientation.X, math.rad(90), Block.Orientation.Z)

I believe it would just be

CFrame.new(endPos) * CFrame.Angles(Block.Orientation.X, math.rad(90), Block.Orientation.Z)

if you meant to add the 90 degrees onto the Y

CFrame.new(endPos) * CFrame.Angles(Block.Orientation.X, Block.Orientation.Y + math.rad(90), Block.Orientation.Z)

Weird, I had already tried that and it didn’t work, but now it did yay.

1 Like