"Position cannot be assigned to" error

I’m trying to change the character’s Right Shoulder Motor6D C1 Position to this:
image

However, when I try to change it through my code, it gives this error in the output:
Position cannot be assigned to

Here’s my code:

local character = player.Character
character:WaitForChild("Torso"):WaitForChild("Right Shoulder").C1.Position = Vector3.new(-0.3, 1.3, 0.2)

If anyone knows how to fix this, please let me know! Thanks :slight_smile:

You have to assign C1. Position is a read-only property of the CFrame.

C1 = C1.Rotation + pos

1 Like

Mind elaborating a bit? I’m new to programming and trying my best to learn! Thanks

A CFrame is not a Position and/or Orientation. Constructing a CFrame is also relative, more can be found out in the API docs.


As @Sharksie has shown:

Motor6D.C1 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(-.3,1.3,.2)

But you can also construct using a Vector3, which will be based on Worldspace instead of relative:

Motor6D.C1 = CFrame.Angles(0,math.rad(90),0) + Vector3.new(-.3,1.3,.2)



More can be read here:

1 Like


Nevermind! I just asked ChatGPT (the AI chat bot) and it perfectly explained it.

I love AI

AI can be helpful, but keep in mind that AI can also be confidentially wrong. In this case, it’s mostly correct, however it did not include the orientation. Setting a CFrame with purely only a position will result in no rotation whatsoever.

Oh you’re right! I asked the AI to fix the code and it did. Thanks for the heads up!

This is the final code:

local character = player.Character
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local originalCFrame = rightShoulder.C1
local objectSpace = originalCFrame:ToObjectSpace(CFrame.new())
objectSpace = CFrame.new(Vector3.new(-0.3, 1.3, 0.2)) * objectSpace
local newCFrame = originalCFrame:ToWorldSpace(objectSpace)
rightShoulder.C1 = newCFrame

Not going to rely entirely on AI, just an incredibly useful tool!

objectSpace wouldn’t be needed as the Motor6D (and most attachments) are relative by default. All you need is one of the following:

Ohhh! I see, okay, thanks! I’ll mark yours as solution.

You can mark @Sharksie’s answer as the solution as they answered correctly first (although missing a little bit of information).

But anyway, good luck with your project :+1:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.