Rotating grouped parts using script

This is the question that is bothering me alot of time cause normal parts have properties to alter but when i grouped the parts the properties is gone so how can i move or rotate the grouped parts using script?

1 Like

You can use SetPrimaryPartCFrame, to set both the orientation and position of a Model. This takes a CFrame object as a parameter, not the Orientation and Position values a Part takes, of course.

3 Likes

Using this method is extremely dangerous, because a repetitive use of this function will cause an offset of parts as shown here:


Notice how the blue and red block used to be together, but after excessive primary part setting, they are offset from each other.

The most efficient way would be to weld the parts together and CFrame ONLY an axis part. That would minimize any anomalies. This is a pretty good reference to what I’m talking about: Introduction to Tweening Models. I’ll show you how to accomplish this.

Have your model ready, and have a part in the model called “Axis” in which the model will rotate around. Here’s a weld function that’ll weld your model to the Axis, and a loop that’ll spin your model.

local function weldToPart(model, part)
	for _, Part0 in pairs(model:GetDescendants()) do
		if Part0:IsA("BasePart") and not (Part0 == part) then
			local WeldConstraint = Instance.new("WeldConstraint")
			WeldConstraint.Part0 = Part0
			WeldConstraint.Part1 = part
			WeldConstraint.Parent = WeldConstraint.Part0
			Part0.Anchored = false
		end
	end
end
-- Weld Model Function

local model = game.Workspace.RotatingModel
weldToPart(model, model:WaitForChild("Axis")
-- Weld Parts in Model to "Axis"

game:GetService("RunService").Heartbeat:Connect(function()
	model.Axis.CFrame = model.Axis.CFrame * CFrame.Angles(0, math.pi/100, 0)
end)
-- Rotate the Model
2 Likes