Making a functional analog clock?

So, I’m trying to make a functional grandfather clock, the bottom part wont move, but I want the clock on top to be synced with os.time.

My two questions:

1 | How do I use os.time in the first place and what values would be useful to me?

2 | How do I transform the numbers from os.time into numbers I can use to rotate the clock hands?

The clock goes down to the second, and the hands will be rotated according to a number obtained from doing some kind of math. Currently the hands have a part at the center of the clock(Primary Part) and the hand all in 3 different models for the 3 hands.

I don’t really expect any replies since my scripting friends were even puzzled by this and it seems to be a pretty difficult thing to do but hey, maybe someone here is smart enough to do it.

1 Like

Ive made some advancements:

image

How could I translate this data into the clocks hand positions?

You probably will find more use in os.date("*t"), which returns a table like this:

{
    ["day"] = 5,
    ["hour"] = 22,
    ["isdst"] = false,
    ["min"] = 12,
    ["month"] = 12,
    ["sec"] = 38,
    ["wday"] = 1,
    ["yday"] = 339,
    ["year"] = 2021
}

Using the sec, hour, and min fields, you can convert these into a 3D rotation by using CFrame.Angles. For example:

CFrame.Angles(math.deg(hour / 12), 0, 0)

Hopefully that helps you out without spoiling the whole thing!

1 Like

This is what I did to find the table after looking into more stuff.

local OSTIME = os.date("*t",os.time()) 

My main issue now is the math I would use to translate it into the 3d rotations, and how I would rotate it.
Any other pointers?

Currently I have it set up with 3 hands, all models, with a primary part in the middle of the clock, and the hand.

Picture of clock:

Im mainly confused as I’ve never used Angles really, and im terrible with math.

Picture of my bad grades:

Whoops, I bungled my math a bit earlier. Say you’re doing seconds - you would divide the sec field by 60, then multiply 360 degrees (the number of degrees per full rotation). Throw the whole thing in math.rad. Alternatively, you can just multiply by math.pi*2 (the number of radians per full rotation).

I would recommend using Attachments. Then, you can attach parts as you see fit using constraints.

local part = script.Parent
local attachSec = part.AttachmentSeconds

local baseCFrame = attachSec.CFrame

local function update()
    local t = os.date("*t")
    attachSec.CFrame = baseCFrame * CFrame.Angles(0, math.rad(t["sec"]/60*360), 0)
end

update()
game:GetService("RunService").Stepped:Connect(update)

Edit: CFrame.Angles expects radians for the X, Y and Z parameters. You can convert degrees to radians by using math.rad, and vice versa with math.deg.

Big words, I’ll try to ask my friend to help translate this stuff for me into something at my level. Thanks for the help, I might come back with more questions :sweat_smile: .

1 Like

Got it working with the help of my friend!
However; we’ve run into the issue which I brought up before, but he thought it could be simply solved with getting the rotation of a different part.

When rotating the clock to an angle not opposite to the one its currently at, the hands go through the clock instead of going the right way.

2021 12 05 23 51 36 - YouTube

How could I fix this? Thanks for all your previous help!

You would have to multiply the CFrame of a part in the model so the hands’ rotations are composed properly. That’s a bit much to explain, though. I gave it a whirl myself, check mine out:

Clock.rbxm (6.2 KB)

Thanks, i’ll check it out later. As you may have seen by the clock in the video its now 1am for mw and i have school tomorrow, haha.

1 Like

The way we set up our clock was so that it just rotates the part manually using MovePrimaryPartCFrame with a part at the center, what numbers could we plug in to make it orient properly?