Confusion about SetPrimaryPartCFrame(CFrame.new())

As a newer coder needing to make a model copy itself alot I am trying to find more understandable info on this.

Here is the code I currently have, it runs fine with no errors, but doesn’t work as the dev hub described. I’m not gonna label this as a bug because I think i’m just doing it wrong.

for count = 0, 269999999973, 27 do  
	local track = game.ServerStorage.TrackPiece:Clone()
	track.Parent = game.Workspace.Tracks
	track.PrimaryPart = game.ServerStorage.TrackPiece.TieMain
	track:SetPrimaryPartCFrame(CFrame.new(count, 0.6, 22.5))
	
	wait(0.1) 
	print(count)
end

This is the result from the preceding script

It only pastes the Primary part over and over again and doesnt paste the whole group like drescibed here: " All other parts in the model will also be moved and will maintain their orientation and offset respective to the Model.PrimaryPart ."

I could really use some help here, thanks

I believe you’ll need to weld the other parts in order for the actual Model to be moved altogether if you haven’t done so already?

Can you share the place file? That sounds like it should work just fine.

Try this code instead, and make sure all the parts are Anchored if they’re set to CanCollide = false

for count = 0, 269999999973, 27 do  
	local track = game.ServerStorage.TrackPiece:Clone()
	track.Parent = game.Workspace.Tracks
	track.PrimaryPart = track.TieMain --Changed this, even though if you had the part set as the PrimaryPart before cloning, you shouldn't need to re-set the PrimaryPart.
	track:SetPrimaryPartCFrame(CFrame.new(count, 0.6, 22.5))
	
	wait(0.1) 
	print(count)
end
4 Likes

I tried making my primary part one which is welded to everything in a bit of a spider web type way, it still didn’t work.

Did you try @MrLonely1221 's solution?
I was able to both recreate and fix your problem in my studio using his solution, even when the track was entirely unanchored

If this still doesnt work it might just be better for everyone to, again, just send the place file

2 Likes

Wow this worked!

Thanks so much y’all!

Sorry for the late response, wrote this then went to bed. Am very happy right now!

1 Like