Can't be assigned to [ERROR]

Hello. I’ve ran into a problem where I’m trying to sync the C0’s of my current player from another character. I keep getting this “Can’t be assigned to” error and I’m confused why.

Code:

-- Services --
local Players = game:GetService('Players')
-- Variables --
local NewBody = script:WaitForChild('NewBody')
---

-- New Char --
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Humanoid = Character:WaitForChild('Humanoid')
		local Torso = Character:WaitForChild('Torso')
		-- Scan & Replace --
		if Humanoid and Humanoid.Health > 0 then
			for Char,BasePart in ipairs(Character:GetDescendants()) do
				if BasePart:IsA('BasePart') then
					-- Replace --
					BasePart.Size = NewBody:FindFirstChild(BasePart.Name).Size
					if BasePart.Name == 'Torso' then
						for _,M6D in ipairs(Torso:GetDescendants()) do
							if M6D:IsA('Motor6D') then
								-- Replace --
								M6D.C0.Position = CFrame.new(NewBody:FindFirstChild('Torso'):FindFirstChild(M6D.Name).C0.Position)
							end
						end
					end
				end
			end
		end
	end)
end)
---

Error:

-- Services --
local Players = game:GetService('Players')
-- Variables --
local NewBody = script:WaitForChild('NewBody')
---

-- New Char --
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Humanoid = Character:WaitForChild('Humanoid')
		local Torso = Character:WaitForChild('Torso')
		-- Scan & Replace --
		if Humanoid and Humanoid.Health > 0 then
			for Char,BasePart in ipairs(Character:GetDescendants()) do
				if BasePart:IsA('BasePart') then
					-- Replace --
					BasePart.Size = NewBody:FindFirstChild(BasePart.Name).Size
					if BasePart.Name == 'Torso' then
						for _,M6D in ipairs(Torso:GetDescendants()) do
							if M6D:IsA('Motor6D') then
								-- Replace --
								M6D.C0.Position = CFrame.new(Vector3.new(NewBody:FindFirstChild('Torso'):FindFirstChild(M6D.Name).C0.Position)) 
							end
						end
					end
				end
			end
		end
	end)
end)
---

I tried to convert the position to vector3 so that the CFrame could receive at least some values


I’m still getting the same error

You cant Assign a CFrames Position by itself, you have to assign it like this:

M6D.C0 = M6D.C0 * CFrame.new(NewBody:FindFirstChild('Torso'):FindFirstChild(M6D.Name).C0.Position)

or:

M6D.C0 = CFrame.new(NewBody:FindFirstChild('Torso'):FindFirstChild(M6D.Name).C0.Position)

And for Orientation, you use CFrame.Angles instead of CFrame.new

The 2nd one did this :sob:
image

I’m trying to make it look like this
image

The issue with the code is that M6D.C0.Position is not a direct property that can be assigned to. Instead, it needs to be set using the Motor6D/C0 property. Here’s the modified code that should work:

-- Services --
local Players = game:GetService('Players')
-- Variables --
local NewBody = script:WaitForChild('NewBody')
---

-- New Char --
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Humanoid = Character:WaitForChild('Humanoid')
		local Torso = Character:WaitForChild('Torso')
		-- Scan & Replace --
		if Humanoid and Humanoid.Health > 0 then
			for Char,BasePart in ipairs(Character:GetDescendants()) do
				if BasePart:IsA('BasePart') then
					-- Replace --
					BasePart.Size = NewBody:FindFirstChild(BasePart.Name).Size
					if BasePart.Name == 'Torso' then
						for _,M6D in ipairs(Torso:GetDescendants()) do
							if M6D:IsA('Motor6D') then
								-- Replace --
								M6D.C0 = NewBody:FindFirstChild('Torso'):FindFirstChild(M6D.Name).C0
							end
						end
					end
				end
			end
		end
	end)
end)

Note that I replaced M6D.C0.Position with M6D.C0 to set the entire C0 property to the value retrieved from the NewBody model.

1 Like

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