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

How do you rotate a "Part", and have workspace as it's parent?

How do you rotate a "Part"?? I want this to be a function, so it's a mousebuttondown, event.

Can you tell me how to make it rotate, at an axis, like what makes it rotate at a X axis, and what makes it rotate, at a Y axis.

2 answers

The rotation of a Part is specified by the rotation matrix component of the CFrame property, you can set the rotation of a Part using a MouseButton1Down event like-so:

mouse = player:GetMouse() --"player" is a reference to the player object
part = workspace.SomePart --The part that you want to rotate

mouse.MouseButton1Down:connect(function()
	part.CFrame = part.Position + CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end)

Where x, y, and z are the angles in degrees to rotate around each axis

If you want the effects of rotation to be cumulative (adding a bit on each time), then use this instead for the rotation line:

part.CFrame = part.CFrame * CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
mouse = player:GetMouse() --"player" is a reference to the player object
part = workspace.SomePart --The part that you want to rotate

mouse.MouseButton1Down:connect(function()
    part.CFrame = part.Position + CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end)

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