Attempt to perform arithmetic (unm) on CFrame

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want my CFrame to not error please.

  2. What is the issue? Include screenshots / videos if possible!
    It errors “attempt to perform arithmetic (unm) on CFrame”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Googling this error returns absolutely NOTHING about it, a couple of arithmetic (unm), but none of it is to do with CFrames

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local offset = CFrame.new(4, 2, 0)
local rPos1 = root.CFrame * -offset * CFrame.new(0, 0, 2).Position

Second line errors, root is HumanoidRootPart

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

You can’t multiply an entire CFrame object by a value instead you need to multiply each of the 3 individual components of the CFrame object by that value. Then you can create a new CFrame object using the 3 previously calculated values. For example:

local num = 0 --whatever number you desire
local newCFrameX = root.CFrame.X * num
local newCFrameY = root.CFrame.Y * num
local newCFrameZ = root.CFrame.Z * num
local newCFrame = CFrame.new(newCFrameX, newCFrameY, newCFrameZ)

What do you mean by value? offset is a CFrame

My bad, I didn’t go through your entire post, I thought offset was just a number value you were attempting to scale the CFrame object by, can you share what is shown in console when you test the game in studio?

1 Like

unm is unary multiplication (aka the -offset which is -1 * offset)
You cant do that for a cframe

1 Like

Change the second line to

local rPos1 = root.CFrame * CFrame.new(offset.X*-1, offset.Y*-1, offset.Z*-1) * CFrame.new(0, 0, 2).Position

You can’t negate a CFrame object.

1 Like

You can also change it to

local rPos1 = root.CFrame * offset:Inverse()* CFrame.new(0, 0, 2).Position

Think of the inverse of a CFrame as the negative of the CFrame.

1 Like

Yes, but my explanation shows where he went wrong and how you are actually supposed to negate individual values if needed in the future.