How do i make a part rotate in a viewport frame using scripts

i would like to know how to make a part rotate within a viewport frame using scripts, as shown in the title of this post. i found some things that could’ve helped me but to no avail.

i assume the script would be easy, since its just rotating a part along its X axis indefinitely at a set angle. Still, i would like some help for this task.

-- First option
local Part = Instance.new("Part")
Part.CFrame = Part.CFrame:ToObjectSpace() * CFrame.Angles(math.pi / 2, 0, math.pi / 2)
Part.Parent = workspace

-- Second option
Part.CFrame = Part.CFrame * CFrame.Angles(0, math.rad(15), 0)
1 Like

it’s kinda just as simple as using tweening or using a while loop

here’s how i’d do it:

put a local script inside the viewport frame, then put this code in

local spinTime = 1 -- adjust to whatever speed you want (lower = faster)
local part = script.Parent.Part
local info = TweenInfo.new(spinTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)
local properties = {Orientation = Vector3.new(180, 0, 0)}

game:GetService("TweenService"):Create(part, info, properties):Play()
1 Like

where do i put this, and what script do i use

Put this in a server script inside the part:

local Part = script.Parent
local rad = 15

while task.wait() do
   Part.CFrame = Part.CFrame * CFrame.Angles(0, math.rad(rad), 0)
end

thanks a lot man, i really appreciate your help again

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.