Trying to Rotate Welded Parts

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:
image
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:
image

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.

2 Likes

anyone? I’ve been struggling on this all day

1 Like

Using rigid constraint should be better as it is like a weld but more visualized with attachments.

Therefore you can control the pivot point using studio tools and change the center of rotation and such.

1 Like

Have you not considered using a HingeConstraint and set the ActuatorType to Motor. If you want them to behave like true clock hands, that seems the simplest method by using a separate one for each hand.

I considered both of these, but I could only use normal welds, not constraints as they were not compatible with the rest of my project, but thanks guys, I found the solution, you have to change the CFrame around the welds, and set the part you are moving to C0, here was my code for anyone else still trying to achieve this:

Centre.Hours.C0 = CFrame.new(Vector3.new(0, -0.8, 0)) * CFrame.Angles(math.rad((hour12 * 30)+minutes), math.rad(0), math.rad(0))
Centre.Mins.C0 = CFrame.new(Vector3.new(0, -1.25, 0)) * CFrame.Angles(math.rad(plrminutes * 6), math.rad(0), math.rad(0))
Centre.Seconds.C0 = CFrame.new(Vector3.new(0, -1.5, 0)) * CFrame.Angles(math.rad(plrseconds * 6), math.rad(0), math.rad(0))

Centre is the part with the weld in, Hours/Mins/Seconds is the name of the weld, the first Vector3 is the position offset of C0’s weld, and the values in CFrame.Angles() just need to be the math.rad() of whatever angle you want to set it to. Doing it like this means that it doesn’t add on the rotation like it would normally with CFrames, and also rotates the part 0 around the weld, respective of the pivot.