I’m trying to rotate 2 clock hands with custom pivot points, both are welded to the centre of the clock using welds (not WeldConstraints, this is compulsory, can only change what part they are welded to). The Clock hands either won’t rotate around their custom pivot points, or if I use CFrames and PivotTo() then it has some extremely weird bugs such as changing position. I need their position to remain the same, and their rotation to be relative to the clock, which I hoped I could achieve by manipulating C0 and C1 of the weld. If anyone could point me in the right direction as to what to do, or show me what I am doing wrong, that would be extremely appreciated.
Explorer:
Parts Model contains all the parts of the clock, Cylinder.001 is the main body of the clock, and inside it are all the welds between it and Parts. Hours and Minutes are the clock hands, and Centre is the Centre of the clock, where the hands should rotate around.
This is the Clock:
And this is the Script:
local HourHand = script.Parent:WaitForChild("H")
local MinuteHand = script.Parent:WaitForChild("M")
local prevXcoor = 0
--local HourWeld = script.Parent:WaitForChild("Cylinder.001").Hours
--local MinuteWeld = script.Parent:WaitForChild("Cylinder.001").Minutes
task.wait(3)
while true do
local plrhours = tonumber(os.date("%H", os.time()))
local plrminutes = tonumber(os.date("%M", os.time()))
local hour12
if plrhours >= 12 then
hour12 = plrhours - 12
else
hour12 = plrhours
end
local minutes = plrminutes * 0.5
print("Hour Angle:".. hour12+minutes)
print("Minute Angle: "..plrminutes*6)
local function RotateHand(hand, xCoor)
local currentPivot = hand:GetPivot()
local Pivot = hand.CFrame * CFrame.new(2,.5,1)-- This is the pivot its relative to the world point , here its the top right corner of the part (the default part of size 4,1,2)
if hand.Name == "Hours" then
Pivot = hand.CFrame * CFrame.new(-0,-0.777,-0)
elseif hand.Name == "Minutes" then
Pivot = hand.CFrame * CFrame.new(0,-1.312,0)
end
local Offset = Pivot:Inverse() * hand.CFrame
Pivot *= CFrame.Angles(math.rad(xCoor-hand.Rotation.Y),0,0)
hand.CFrame = Pivot * Offset
local newCFrame
--newCFrame = currentPivot * CFrame.Angles(math.rad((xCoor - hand.Rotation.Y)), math.rad(0), math.rad(0))
--newCFrame = currentPivot * CFrame.Angles(math.rad((xCoor - hand.Rotation.Y)), math.rad(0), math.rad(0))
--hand:PivotTo(newCFrame)
hand.Rotation = Vector3.new(-90, xCoor, -90)
end
--RotateHand(HourHand, -100)
--RotateHand(MinuteHand, 180)
HourHand.Part.Hours.C0 = CFrame.new(HourHand.Part.Hours.Part0.Position)
task.wait(.5)
end
(the comments are all remnants of other methods I have tried)
Any help would be greatly appreciated.