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.
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 .
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.
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:
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?