Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to access all the parts in a model and change there position???

So I want to duplicate a model of an R15 rig, and then I want to move the position of all the parts that can have their position moved. I started using an in pairs loop to get all the parts. But then I don't know what to do from there. I was thinking maybe doing every part that can be moved in the model and teleporting it, but that can't be efficient.

This is the script I'm thinking of:

--Sorry for the sloppy script
for i,v in pairs(Cv:GetChildren()) do
				
	if v.Name == "LeftFoot" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end
	
	if v.Name == "RightFoot" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end	
	
	if v.Name == "LeftLowerArm" then
		 v.Position = game.Workspace.EnemySpawn.Position
	end
	
	if v.Name == "LeftUpperArm" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end	
	
	if v.Name == "RightLowerArm" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end	
	if v.Name == "RightUpperArm" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end	
	
	if v.Name == "LeftHand" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end	
	
	if v.Name == "RightHand" then 
		v.Position = game.Workspace.EnemySpawn.Position 
	end		
					
end

I was just wondering if the fine people of scripting helpers could help me find a more efficient way. Thank you for your time.

3 comments

0

I would use Model:SetPrimaryPartCFrame()

0

Set a PrimaryPart on the model by clicking the property and then the part inside the model you want it to be the PrimaryPart. Then on the script use model:SetPrimaryPartCFrame(CFrame). It will change the CFrame of the primary part you have set and the other model parts will keep their position/orientation in relation to the primary part.

0

Set a PrimaryPart on the model by clicking the property and then the part inside the model you want it to be the PrimaryPart. Then on the script use model:SetPrimaryPartCFrame(CFrame). It will change the CFrame of the primary part you have set and the other model parts will keep their position/orientation in relation to the primary part.

1 answer

✓ Accepted answer

If you just want to move the model you can move it by moving the PrimaryPart. If you don't have a PrimaryPart set, you can do it from the Properties editor in studio, or via a script (model.PrimaryPart = part).

Then you can do model:SetPrimaryPartCFrame(CFrame.new(x, y, z)) to give it a new Position or if you want to move it by x in a specific direction:

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() + Vector3.new(xOffset, yOffset, zOffset))

Hope this answered your question.

This discussion is preserved as it was. New answers, comments, and votes are closed.