UpVector cannot be assigned to

So just a few minutes ago I found a post stating that you can move a part left/right based on it’s orientation by multiplying its RightVector. I tried it out with UpVector but it says that UpVector cannot be assigned to. Can anybody help me out?
BTW here’s the code I’m using:

local runService = game:GetService("RunService")
local point = script.Parent
local cframeAmount = point.CFrame
local random = Random.new()
runService.Heartbeat:Connect(function()
	local Outoffsetno = random:NextNumber(0, 2)
	local chooseOperation = math.random(1, 2)
	if chooseOperation == 1 then
		point.CFrame.UpVector *= Outoffsetno
	else
		point.CFrame.UpVector *= Outoffsetno
	end
	task.wait(random:NextNumber(1, 2))
end)

You can’t modify any of the properties of CFrames, you would have to create a new CFrame with the applied change.

UpVector is a unit Vector3 property of CFrame, and subsequently part of the CFrame matrix. You can do vector addition to a CFrame to get another CFrame. In your case it would look like this:

local runService = game:GetService("RunService")
local point = script.Parent
local cframeAmount = point.CFrame
local random = Random.new()
runService.Heartbeat:Connect(function()
	local Outoffsetno = random:NextNumber(0, 2)
	local chooseOperation = math.random(1, 2)
	if chooseOperation == 1 then
		point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno
	else
		point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno
	end
	task.wait(random:NextNumber(1, 2))
end)
1 Like

Alright, I’ll try this out in a bit (once again on my study laptop sigh)

1 Like

the problem is CFrame cannot be set but you have to create another CFrame value and then do the operation.

That is why I did vector addition on the CFrame value. You can multiply a Vector3 by a scalar. You can also add a Vector3 to a CFrame. Since UpVector is a unit vector that is part of the CFrame matrix, adding it multiplied by a scalar gives the desired result.

You can see this by inserting a Part into workspace and doing the following:

workspace.Part.CFrame = workspace.Part.CFrame + workspace.Part.CFrame.UpVector * 5

This is the same as

workspace.Part.CFrame = workspace.Part.CFrame * CFrame.new(0,5,0)

Let’s say it kind of works…
Pic01
It’s going up and down a lot more than before. How would I neutralize this effect?

multiply Outoffsetno by a scalar (say 0.5?)

1 Like

Alright, I’ll try this later. Thanks :slight_smile:

1 Like

Still doesn’t work, I tried just multiplying cframeAmount’s UpVector so that it will ALWAYS have to be near it’s origin CFrame. Even multiplying Outoffsetno by 0.25 didn’t help

What are you trying to accomplish with this so I can better solve your problem?

Basically I want my point(s) to move up and down on its axis (UpVector) even if it’s been rotated.

@Scarious My goal is to move my points up and down (but not too much) on its axis (UpVector) even while the points are rotated

You can always move objects a certain direction by multiplying the object’s CFrame to the direction you’re aiming for.

The following will shift the part upwards by 5 units.

Part.CFrame = Part.CFrame * CFrame.new(0, 5, 0)

The following will shift the part forward using its lookVector (facing direction) by 5 units.

Part.CFrame = Part.CFrame + Part.CFrame.lookVector * 5

You can plug in your directional values after multiplying the part’s CFrame

Part.CFrame * (yourDirection * SomeScalerUnit)

Quick heads up, you cannot multiply a CFrame by a Vector3, instead you should be adding the Vector3 to the CFrame, so when you say

it should be

Part.CFrame = Part.CFrame + Part.CFrame.LookVector * 5

same with the second part when you say,

it should be

Part.CFrame = Part.CFrame + (yourDirection * SCALAR)

As soon as you update your post to match this information lmk so I can remove this from my response.


Anyways, back to the problem at hand @NeoGaming_RBLX,

when you do your addition of point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno, Outoffsetno is a scalar. This is why I told you to multiply it by another scalar, for which the example I provided was 0.5, and you subsequently tested 0.25. Based on your code, the maximum value of this offset scalar is 2, and multiplying it by 0.25 would give us 0.5 studs. Anyways, when you say that you want it to be near its origin CFrame, would I be right to assume the following:

That you want the parts to be located on this red line, and that you currently have it unintentionally offset? And are trying to move them by the blue line offsets?

1 Like

Right, I forgot about that. I’m a bit rusty. :laughing:

I should of written:

Part.CFrame = Part.CFrame + Part.CFrame.lookVector * 5

I’m not sure if this is what you intended either, since Part.CFrame = Part.CFrame * CFrame.new(0,0,-5) is not the same as what you put.

This would be like trying to do Part.CFrame = Part.CFrame * CFrame.new(0,5,0), and instead doing:

local upvec = Part.CFrame.UpVector* 5
Part.CFrame = Part.CFrame * CFrame.new(-upvec.X, -upvec.Y, -upvec.Z)

Sorry that this sounds like I’m trying to attack you, but that’s not my intent, I’m just trying to help.

I was just correcting my syntax mistake.

Yes, that’s exactly what I want. The offset goes WAY MORE than it did before I implemented your solution
PS: I also want it to go lower, the code I sent in the original post had a typo and had 2 *

Can you post the entirety of your existing code so I can do some problem solving on it and reach the result you want? You can also opt to send me your .rbxl or .rbxlx file instead.

1 Like