Part.Orientation = Part2.CFrameLookVector not working

The orientation in my script is not working. Everything else works fine. By the way, “beam” is a part.

Script

local tool = script.Parent
local TS = game:GetService("TweenService")

tool.Activated:Connect(function()
	local character = tool.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	local humanoid = character:FindFirstChild("Humanoid")
	local sound = tool.chez
	sound:Play()
	wait(0.3)
	local beam = game.ReplicatedStorage.cheeseBeam:Clone()
	
	beam.CurrentDmgAmount.Value = 100
	
	beam.cheeseBeamAttachment.Parent = character.Torso
	
	beam.ProtectedUserId.Value = player.UserId
	
	beam.Parent = character.Torso.cheeseBeamAttachment
	
	--beam.CFrame = CFrame.lookAt(character.Torso.CFrame.LookVector, character.Torso.CFrame.LookVector, Vector3.new(0, 0, 1))
	
	beam.CFrame = character.Torso.cheeseBeamAttachment.WorldCFrame --+ character.Torso.CFrame.LookVector + Vector3.new(0, 0, 1.8)
	
	game:GetService("Debris"):AddItem(beam.Parent, 1)
	
	beam.Orientation = character.HumanoidRootPart.CFrame.LookVector -- everything else is fine, but this doesn't do anything
	

	
	local transTweenGoals = {}
	transTweenGoals.Transparency = 1
	local mainTweenInfo = TweenInfo.new(1)
	local transTween = TS:Create(beam, mainTweenInfo, transTweenGoals)
	transTween:Play()
	
	local transTweenGoals2 = {}
	transTweenGoals2.Brightness = 0
	transTweenGoals2.Range = 0
	
	local transTween2 = TS:Create(beam.PointLight, mainTweenInfo, transTweenGoals2)
	transTween2:Play()
	
	local transTweenGoals3 = {}
	transTweenGoals3.Rate = 0
	
	local transTween3 = TS:Create(beam.ELECTRIC, mainTweenInfo, transTweenGoals3)
	transTween3:Play()
	
	
	local lengthTweenGoals = {}
	
	lengthTweenGoals.Size = Vector3.new(5.199, 5.199, 15.127)
	
	local lengthTween = TS:Create(beam, mainTweenInfo, lengthTweenGoals)
	lengthTween:Play()
	
	local lengthTweenGoals2 = {}

	lengthTweenGoals2.CFrame = beam.CFrame + character.HumanoidRootPart.CFrame.LookVector * 75 --Vector3.new(0, 0, -15.128)
	
	local lengthTween2 = TS:Create(beam, mainTweenInfo, lengthTweenGoals2)
	lengthTween2:Play()
	
	local dmgTween = TS:Create(beam.CurrentDmgAmount, mainTweenInfo, {Value = 1})
	dmgTween:Play()
	
end)

Any help appreciated!

From what I see, Orientation is a Vector3. Thus, you’d have to use the part’s CFrame rather than it’s Orientation

That’s my two cents, I’m not great at modifying CFrames, so can’t help much here unfortunately

Orientation is a Vector3 yes, but he shouldn’t use the part’s CFrame, he should get the Part’s position instead as it is a vector3. (Part.Position or Part.CFrame.Position)

beam.Orientation is the X Y Z rotation in degrees.

LookVector is a length-one vector pointing in the forward direction of the CFrame.

The reason nothing happens is because all the elements of the look vector are [-1, 1] so the most it can rotate each axis is like 1 degree, so it’s too small to see probably.

You can convert a LookVector to an untranslated CFrame by doing:

CFrame.lookAt(Vector3.zero, lookVector)

You can convert that CFrame to an orientation by using this code:

-- By @sleitnick:
local rx, ry, rz = cframe:ToOrientation()
local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz)

-- In vector3 format:
local orientation = Vector3.new(dx, dy, dz)

One question for answering this question is what orientation you’re trying to get there?

If you want to have beam point at the character, you can do that more simply like this:

local lookVector = character.HumanoidRootPart.CFrame.LookVector
-- Have the beam CFrame look in the direction of the HRP (but still keep the rough up direction)
beam.CFrame = CFrame.lookAt(beam.Position, beam.Position + lookVector, beam.CFrame.UpVector)
1 Like

This doesn’t do anything that makes sense because the units are degrees/rotation and studs/length. Do you mean to have beam.Position instead of beam.Orientation?

Reply:

In the title it says beam is a Part. The OP also uses beam.CFrame without errors, so it’s probably a Part.

It’s beam.Attachment0 (or Attachment1).CFrame because beam doesn’t have a CFrame property.

Reply:

I thought he named Beam as a Part, not as in it being a Basepart, if so, then my bad. I just wasn’t awake 2 hours ago, haha.

This too, I’m talking if he wants to continue LookVector

im trying to get the beam (a variable which is actually a Part) to point the direction of the character.

i do. unless theres a easier way

just a reminder, i want to get the beam ( a part ) to point the direction of the character

@Xx_LightningX @BendsSpace

1 Like

You can just do:

Part.CFrame = CFrame.new(Part.Position) * Part2.CFrame.LookVector
1 Like

If you want the beam (part) point to the direction of the character… we can use CFrame

We can set the first argument to be the beam’s position and the second argument to be the Character’s Torso CFrame so that it points to it.

So essentially:


beam.CFrame = CFrame.new(beam.Position, character.Torso.cheeseBeamAttachment.Position)

So we don’t need to be using the orientation property, as the CFrame arguments handle everything you need, the first argument is for the position of the beam and the second argument is where it will be pointing at (it determines the direction to point at)

Using the Part:

Part.CFrame = CFrame.new(Part.Position, Part2.Position)

thank you good sir! very much appreciated!

1 Like