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

Is there a new way to get a model CFrame?

I was using the :GetModelCFrame() for rotating a entire model with this script. The problem is that this function is deprecated and I'm looking for a new way to get the model CFrame...

function TransformModel(objects, center, new, recurse)
	for _,object in pairs(objects) do
		if object:IsA("BasePart") then
			object.CFrame = new:toWorldSpace(center:toObjectSpace(object.CFrame))
		end
		if recurse then
			TransformModel(object:GetChildren(), center, new, true)
		end
	end
end

And the lines to call the function:

local center = NewModel:GetModelCFrame()
TransformModel(
	NewModel:GetChildren(),
	center,
	center * CFrame.Angles(0, math.rad(90), 0),
	true
)

If there is a better way to rotate a model, tell me! Thanks for the help if somebody can!

1 answer

You are encouraged to use GetPrimaryPartCFrame and SetPrimaryPartCFrame.

GetPrimaryPartCFrame is basically just model.PrimaryPart.CFrame.

:SetPrimaryPartCFrame(new) is basically TransformModel(model:GetChildren(), model.PrimaryPart.CFrame, new, true).

These use the .PrimaryPart of a model to determine which direction / position defines the model -- you have to have this set for the methods to work. You can set with a script or in studio.


The problem with the old methods is that they use inscrutable guesses to decide which way is forward and where the center is.

2 comments

0

The problem is that I already set a PrimaryPart, and I need it to move the model with :SetPrimaryPartCFrame(), and I don't want to set the PrimaryPart to another part ... Do you know if there is a function to get the model's center CFrame?

0

You have to define the center of the model in terms of the primary part.

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