Hi, I have problem, that i need to edit position of existing CFrame, I tried this
cf.Position=servo.Attachment0.Position
but it gives this error: 10:31:54.985 - p cannot be assigned to
Hi, I have problem, that i need to edit position of existing CFrame, I tried this
cf.Position=servo.Attachment0.Position
but it gives this error: 10:31:54.985 - p cannot be assigned to
Roblox’s CFrame datatype is immutable, meaning it cannot be changed.
What is cf
defined as? Maybe I can help more if I see what you’re doing this for.
I have existing cframe, and i need cframe with same rotation, but diferent position
I am asking for where the cf
variable is declared.
You need to make a new CFrame and set that as the CFrame of the thing you’d like to move.
its just cframe from part…
If this is from a part, simply set the Position
from the part to the new position:
part.Position = servo.Attachment0.Position
ok, but i dont want to move the part, i need it for counting some angles, … for aiming canons
You have me confused, you told us earlier that you’d only like to change the position.
ya, but not to chnge real parts position, but just change the position in var
um
local position = cf.Position
You could do that to point to the position, but I seriously don’t get you.
ok, but i need cframe, because then i use pointToWordSpace with it (and that is only reason why i need it)
You can also use a CFrame at this point but I think that you are using it uncorrectly.
Maybe you should try this:
part.CFrame = CFrame.new(Vector3.new(servo.Attachment0.Position))
also if you’d like to change only variable you should declare it as:
local newposition = CFrame.new(Vector3.new(servo.Attachment0.Position))
then you will have a value of Attachment0’s position in variable ‘newposition’.
I hope this helps.
ok, but i need to have there orientation of the part
Insteas of moving it to the part, get the coordinates of the part and use Vector3 to move it.
I have mathematic operation, in that i need cframe with orientation of some part and position of the atachment
Then you should use CFrame.Angles and change the X ,Y, Z variables.
Here is an simple code to use it.
local variable = CFrame.new(Vector3.new(servo.Attachment0.Position)) * CFrame.Angles(Vector3.new(part.Rotation))
You can of course change the operator because I don’t know what posititon you are trying to get.
I hope this helps.
A simpler method would be to negate the current Position and add the attachment’s Position:
local var = (part.CFrame - part.Position) + servo.Attachment0.Position
Here’s a way to only set the Z-axis of a cframe, maintaining the current rotation:
local cframe = CFrame.new(
Vector3.new(part.CFrame.Position.X, part.CFrame.Position.Y, 0))
* part.CFrame.Rotation