This may be very idiotic but I’m kind of having a difficult time trying to remove the last 2 digits from the time as they look a bit weird and unnecessary.
Script in Workspace:
local increase = 0.5 -- hour to add per cooldown
local minutesToRotate = 0.5 --day cycle in minutes
local secondstorotate = minutesToRotate * 60
local cooldown = secondstorotate / (24/increase)
Lighting:SetMinutesAfterMidnight(0)
while true do
Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + increase)
wait(cooldown)
end
Script in TextLabel:
local Lighting = game:GetService("Lighting")
local text = script.Parent
local function setTextTime()
text.Text = Lighting.TimeOfDay
end
setTextTime()
Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(setTextTime)
You can use string.split for splitting the property into three values. Then using two of them.
(Here’s the API reference of string)
Because the property is divided into a colon. We can use the following code:
local Lighting = game:GetService("Lighting")
local text = script.Parent
local function setTextTime()
local values = Lighting.TimeOfDay:split(":") -- Splits a string into ":", returning a table of ordered results.
text.Text = values[1] .. ":" .. values[2] -- We concadenate the different strings together.
end
setTextTime()
Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(setTextTime)
@Tuguicraft’s solution gives you more flexibility, however, if you only need to deal with one string like this in your game, you can safely use string.sub without worrying too much about scalability.