However, when attempting to rotate it from a script, it instead rotates around the center of mass. robloxapp-20230526-2055065.wmv (630.4 KB)
I’d rather not use a HingeConstraint if possible.
Script:
-- Script is in ServerScriptService, hand is the clock hand, and duration is 10.
-- Yes, there's more to the script, but this is the only part that matters here.
for i = 1, duration * 10 do
hand.Rotation += Vector3.new(0, 0, (-360 / duration) * 0.1)
task.wait(0.1)
end
If you want to rotate the hand of the clock around its PivotOffset, you can achieve this by changing the rotation point of the hand. Instead of directly modifying the Rotation property of the hand, you can use the CFrame property to rotate the hand around a different pivot point.
-- Assuming the hand is a child of a Part or Model
local pivotOffset = hand.PivotOffset
-- Set initial rotation
hand.CFrame = hand.CFrame * CFrame.new(pivotOffset)
-- Script is in ServerScriptService, hand is the clock hand, and duration is 10.
-- Yes, there's more to the script, but this is the only part that matters here.
for i = 1, duration * 10 do
local rotation = CFrame.Angles(0, 0, math.rad((-360 / duration) * 0.1 * i))
hand.CFrame = hand.CFrame - hand.CFrame.Position * rotation + hand.CFrame.Position
task.wait(0.1)
end
Thank you for your help! I used :PivotTo and it is now working as intented.
@IchVerwendeKeineTool
I appreciate your reply, but your code had a couple errors in it (lines 5 and 11, “invalid argument #1 (CFrame expected, got Vector3)”). However, I used the rotation value from line 10, so thank you for contributing that!
Final code:
for i = 1, duration / 10 do
local currentPivot = hand:GetPivot()
local rotation = CFrame.Angles(0, math.rad((360 / duration) * 0.1), 0)
hand:PivotTo(currentPivot * rotation)
task.wait(0.1)
end