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

Rotate a model and parent children around center of model

Hi guys; I want to be able to rotate a model around the center of its self. I have this script but it rotates the model around an axis and not the center of the model. Can anyone help me. Thanks

function onClicked()
    rotation=true parts=game.Workspace.Clay_Paky_K20_Beye.Pan:GetChildren() 
	for i=1,#parts do if parts[i]:IsA("Part") then 
		parts[i].CFrame=parts[i].CFrame + Vector3.new(0,0,0) 
		if rotation==true then 
			parts[i].CFrame=CFrame.Angles(0,0.01,0) * parts[i].CFrame 
			else 
		end 
	end 
	end

	
	
end
 
script.Parent.MouseButton1Down:connect(onClicked)

1 answer

function Transform(model, center, new)
	for _,v in pairs(model:GetChildren())do
		if v:IsA("BasePart")then
			v.CFrame=new*center:inverse()*v.CFrame
		end
		Transform(v,center,new)
	end
end

This will transform model by the difference between center and new, new being the new rotation.

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