What is the best way to make a model rotate?


Goal & Issue

I want to make a function that will grab a bunch of models inside of a folder, then have those models rotate in different directions than each other.

My problem is that I’m not exactly sure what the best way to go about it would be. I’m not very educated on CFraming, let alone Model Pivoting; so I’m not sure what the best way to do this would be.

Script

This is what I have currently and it’s very bland to say the least. Each model turns in the same direction & isn’t the most spectacular thing to look at; and I want to change that.

I’m fully aware that this script only does a block at a time, I plan to fully rescript a new Rotation Function; just want to know the best way to do it.

for _,Light in ipairs (game.Workspace.VenueLights[LightingName]:GetChildren()) do
		coroutine.wrap(function()
			local c = Light.CFrame
			while enabled do
				Light.CFrame = Light.CFrame*CFrame.fromEulerAnglesXYZ(0,0.1,0.05)
				wait(0.05)
			end
			Light.CFrame = c
		end)()
	end

Edit

Giving this a bump, if you need any extra information; shoot me a message and i’ll add it in. Going to put a video of what I mean shortly.


Thank you for any help/advice you may give.

1 Like

Here’s a few basic tips to help you get started.

PVInstance:PivotTo() basically allows you to set the model CFrame from its pivot (which can be the pivot you manually set, or a pivot that was automatically set, such as in the center of the model or at the PrimaryPart).

PVInstance:GetPivot() simply grabs the pivot of the model.

If you’re confused, PVInstance is an inherited class from Models, BaseParts, etc.

With these functions in mind, you can rotate a model as such:

model:PivotTo(model:GetPivot() * CFrame.Angles(0, math.rad(DEGREES), 0))

math.rad converts degrees into radians, and CFrame.Angles is equivalent to CFrame.FromEulerAnglesXYZ. In this example, the only axis with a value is the Y axis. Therefore, the model will rotate clockwise on that axis. If you wanted the model to turn counterclockwise, you can simply make the value negative: math.rad(-DEGREES) or -math.rad(DEGREES)


Sorry, fixed that, I often confuse it despite working with it so frequently

3 Likes

I think this should work except for :SetPivot because it doesn’t exist. Use :PivotTo instead.

1 Like