SetPrimaryPartCFrame only setting the CFrame of the PrimaryPart and not the entire model?

SetPrimaryPartCFrame only setting the CFrame of the PrimaryPart and not the entire model? I have never seen this bug before and cannot find anything about it searching around google. The script is as follows:

local TempHolder = Instance.new('Model')
				local Base = Instance.new('Part',TempHolder)
				Base.Size = Vector3.new(150, 1, 150)
				Base.CFrame = CFrame.new(-257.999878, 0.500001013, 6005.99805, 1, 0, 0, 0, 1, 0, 0, 0, 1)
				Base.Anchored = true
				TempHolder.PrimaryPart = Base
				local Walls = Instance.new('Folder', TempHolder)
				local Paths = Instance.new('Folder', TempHolder)
				TempHolder.Parent = workspace
				TempHolder.PrimaryPart = Base
				-- print(printTable(Data))
				if success then
					for _,v in pairs(Data.Purchases) do
						if v then
							if v.Name == 'Wall' then
								local Model = Instance.new('Model')
								Model.Name = 'Wall'
								local WallPart = Instance.new('Part', Model)
								WallPart.Anchored = true
								WallPart.Transparency = 1
								WallPart.Material = Enum.Material.SmoothPlastic
								WallPart.Name = 'Hitbox'
								WallPart.Size = Vector3.new(9, 12, 0.4)
								local Pole1 = Instance.new('Part', Model)
								Pole1.Shape = 'Cylinder'
								Pole1.Name = 'Pole1'
								Pole1.Anchored = true
								Pole1.Transparency = 0
								Pole1.Material = Enum.Material.SmoothPlastic
								Pole1.Size = Vector3.new(9, 0.4, 0.4)
								-- Pole1.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * 0.1
								Pole1.CFrame = CFrame.new(v.Pole1X,v.Pole1Y,v.Pole1Z)
								local Pole2 = Instance.new('Part', Model)
								Pole2.Shape = 'Cylinder'
								Pole2.Name = 'Pole2'
								Pole2.Anchored = true
								Pole2.Transparency = 0
								Pole2.Material = Enum.Material.SmoothPlastic
								Pole2.Orientation = Vector3.new(0,0,math.rad(90))
								Pole2.Size = Vector3.new(9, 0.4, 0.4)
								-- Pole2.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * -0.1
								Pole2.CFrame = CFrame.new(v.Pole2X,v.Pole2Y,v.Pole2Z)
								WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,9,0.4)
								WallPart.CFrame = CFrame.new(
									Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
									Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
								)
								Pole1.CFrame = Pole1.CFrame * CFrame.Angles(0,0,math.rad(90))
								Pole2.CFrame = Pole2.CFrame * CFrame.Angles(0,0,math.rad(90))
								local WallPart3 = Instance.new('Part', Model)
								WallPart3.Anchored = true
								WallPart3.Transparency = 0
								WallPart3.Material = Enum.Material.SmoothPlastic
								WallPart3.Name = 'Wall1'
								WallPart3.Orientation = Vector3.new(0,0,math.rad(90))
								WallPart3.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
								WallPart3.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * 0.1
								local WallPart4 = Instance.new('Part', Model)
								WallPart4.Anchored = true
								WallPart4.Transparency = 0
								WallPart4.Material = Enum.Material.SmoothPlastic
								WallPart4.Name = 'Wall2'
								WallPart4.Orientation = Vector3.new(0,0,math.rad(90))
								WallPart4.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
								WallPart4.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * -0.1
								Model.PrimaryPart = WallPart
								Model.Parent = TempHolder
								---
							elseif v.Name == 'Path' then
								local Model = Instance.new('Model')
								Model.Name = 'Path'
								local WallPart = Instance.new('Part', Model)
								WallPart.Anchored = true
								WallPart.Transparency = 0
								WallPart.Material = Enum.Material.SmoothPlastic
								WallPart.Name = 'Hitbox'
								local Pole1 = Instance.new('Part', Model)
								Pole1.Shape = 'Cylinder'
								Pole1.Name = 'Pole1'
								Pole1.Anchored = true
								Pole1.Transparency = 0
								Pole1.Material = Enum.Material.SmoothPlastic
								Pole1.Size = Vector3.new(0.2, 3, 3)
								-- Pole1.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * 0.1
								Pole1.CFrame = CFrame.new(v.Pole1X,v.Pole1Y,v.Pole1Z)
								local Pole2 = Instance.new('Part', Model)
								Pole2.Shape = 'Cylinder'
								Pole2.Name = 'Pole2'
								Pole2.Anchored = true
								Pole2.Transparency = 0
								Pole2.Material = Enum.Material.SmoothPlastic
								Pole2.Size = Vector3.new(0.2, 3, 3)
								-- Pole2.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * -0.1
								Pole2.CFrame = CFrame.new(v.Pole2X,v.Pole2Y,v.Pole2Z)
								WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,0.2,3)
								WallPart.CFrame = CFrame.new(
									Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
									Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
								)
								Pole2.CFrame = Pole2.CFrame * CFrame.Angles(0,0,math.rad(90))
								Pole1.CFrame = Pole1.CFrame * CFrame.Angles(0,0,math.rad(90))
								Model.PrimaryPart = WallPart
								Model.Parent = TempHolder
							else
								if game.ReplicatedStorage.ItemHolder:FindFirstChild(v.Name) then
									local Thing = game.ReplicatedStorage.ItemHolder[v.Name]:Clone()
									Thing.Parent = TempHolder
									Thing:SetPrimaryPartCFrame(CFrame.new(v.x,v.y,v.z))
								end
							end
						end
						wait()
					end
					TempHolder:SetPrimaryPartCFrame(Tycoon.Base.CFrame)
					for _,v in pairs(TempHolder:GetChildren()) do
						if v:IsA('Model') then
							v.Parent = Tycoon.Purchases
						end
					end
					for _,v in pairs(Walls:GetChildren()) do
						if v:IsA('Model') then
							v.Parent = Tycoon.Purchases.Walls
						end
					end
					for _,v in pairs(Paths:GetChildren()) do
						if v:IsA('Model') then
							v.Parent = Tycoon.Purchases.Paths
						end
					end
					TempHolder:Destroy()
				end

I don’t know what is causing this as I have never had it before, any help would be appreciated, thanks!

You might need to weld everything else to the primary part or to something welded to the primary part.

1 Like

Try using ‘Model’ objects for the walls and paths instead of ‘Folders’.

1 Like

Try to parent the Part after Parenting the Model to Workspace. Anchoring it before parenting is also important.

This is most likely not your problem, but using the second parameter to Instance.new(class,parent) to set the parent is deprecated, its better you do … local obj = Instance.new(“class”) then obj.Parent = itsParent

I copied your code, and when I removed the part where it assigns the CFrame to Primary Part, and I look in explorer at the pieces, they are all spread out, all over the place, some several thousand studs away from each other.
Then I added back the CFraming of the Primary Part, and checked the distances, and they were still the same, spread all over the place, but in relation to the CFrame…
So… The CFraming of the PrimaryPart in your code IS working, its your other calculations setting the CFrame of the individual pieces, that is causing them to be in really spread out places.
Also… perhaps it would be simpler to construct your models, and put them in ServerStorage or ReplicatedStorage, instead of creating them in code each time. Just a suggestion. Good luck.

1 Like

Sorry for the late reply’s, I wasn’t home yesterday.

Okay, thanks. This code is a part of the saving/loading system for my tycoon. I am re-writing it anyway, but thanks!