CFrame of parts don't update when set to another CFrame

I’m trying to test out my knowledge of CFrames, I’m currently playing around with this demo I made that only half works. It consists of 3 parts, two of them grouped in a model. The two parts in the model are supposed to teleport to the third part, which is outside of the model. For some reason, the code doesn’t return any errors, but neither of the two parts in the model change their position.

Code:

(Script is placed in the workspace):

local Model = game.Workspace.Cell
local PPart = game.Workspace.Part
local ModelChildren = Model:GetChildren()
local PrimaryPart = Model.Primary

for _, Children in pairs(ModelChildren) do
	local ChildPosition = Children.CFrame
	local PPartCFrame = CFrame.new(PPart.Position.X, PPart.Position.Y, PPart.Position.Z)
	print(PPartCFrame)
	--local Difference = CFrame.new(ChildPosition.X + PrimaryPart.CFrame.X, ChildPosition.Y + PrimaryPart.CFrame.Y, ChildPosition.Z + PrimaryPart.CFrame.Z)
	ChildPosition = CFrame.new(PPart.Position.X, PPart.Position.Y, PPart.Position.Z)
end
Images:

BEFORE: (Game not yet run)

AFTER: (Same)
image

Any help or suggestions are greatly appreciated!

when you’re doing local ChildPosition = Children.CFrame, you’re storing the CFrame as a variable, so when you do ChildPosition = CFrame.new(PPart.Position.X, PPart.Position.Y, PPart.Position.Z), you’re only changing the value of the variable, not the part’s CFrame. you should instead do Children.CFrame = CFrame.new(PPart.Position).

This worked, thank you so much! I guess I just got confused :sweat_smile:

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