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

Is there a way to rotate a Model?

Hey people! I've recently just figured out how to CFrame -- or move -- Models using MoveTo(), and it has helped me immensely. The thing is, now I want to learn how to rotate a model. It would be VERY helpful if anyone could teach me this skill, because I'm having trouble rotating the WHOLE Model instead of just its individual pieces. Thanks!

1 answer

✓ Accepted answer

Yes, there is a way.

Arguments for the function:

function TransformModel(table objects, CFrame center, CFrame new_center[, bool recursive])

Code:

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:children(), center, new, true)
		end
	end
end

local Model = game.Workspace.ModelToRotate

TransformModel(Model:children(), Model:GetModelCFrame(), Model:GetModelCFrame() * CFrame.new(0, math.rad(45), 0), true) -- Rotates the model 45*.

2 comments

0

Wait. What does argument and code mean? Sorry, I'm a bit of a beginner on this. Do I put them both in separate scripts, or what?

0

Arguments are the inputs to the function. The code is the actual script. The bottom one is the one you use.

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