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)
---
-- 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
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.