local clock = {}
local refreshTime = 0.1
local frame = script.Parent.ImageLabel
local run
function clock.start()
local t
local h
local m
local s
run = true
spawn(function()
while run do
t = game.Lighting.TimeOfDay
h = tonumber(string.sub(t, 1, 2))
m = tonumber(string.sub(t, 4, 5))
s = tonumber(string.sub(t, 7, 8))
--frame.hour.Rotation = h * 36 + m/2
frame.minute.Rotation = m * 6 + 5/10
wait(refreshTime)
end
end)
end
function clock.stop()
run = false
end
return clock
Local:
local clock = require(script.Parent.clock)
clock.start()
I want to make a clock that will move, so I wrote a script, but for some reason nothing happens, although there are no errors. What’s the problem?
These are the math related to your problem(converting TimeOfDay to clock pointer angles):
local function getTime(): (number, number, number)
local x = game.Lighting.TimeOfDay:split(":")
local h, m, s = tonumber(x[1]), tonumber(x[2]), tonumber(x[3])
return h, m, s
end
--in case you don't like string operations
local function getTime2(): (number, number, number)
local s = game.Lighting.ClockTime/24*86400
local h = math.floor(s/3600)
s %= 3600
local m = math.floor(s/60)
s %= 60
return h, m, s
end
local function updateClock(): ()
local hour, minute, second = getTime()
--in degrees
--hour%12 to convert 24 hour clock to 12 hour clock
local hourAngle = (hour%12*60+minute)*360/(12*60)
local minuteAngle = (minute*60+second)*360/(60*60)
--set rotations instead of printing
print("Hour Angle:", hourAngle, "Minute Angle:", minuteAngle)
end
task.spawn(updateClock)
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(updateClock)
In the above code I don’t take into consideration the seconds for the hour pointer angle, that’s because I consider the angle change insignificant(the IRL example of this is that you can’t notice the hour pointer move when you directly look at it).
You can test it with the following code that quickly changes the in-game time:
while task.wait() do
game.Lighting.ClockTime += 0.005
end