How do I remove the last 2 digits of "TimeOfDay"? (Stupid question)

Hi Devs,

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)

Any help please?

Thanks! :slight_smile:
Akridiki

2 Likes

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)
1 Like

here is one of my posts i made recently about time it might help you

also you could use string.sub i guess or you can use MaxVisibleGraphemes of the textlabel but string.sub is better

2 Likes

@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.

str = game.Lighting.TimeOfDay:sub(0,-4))
2 Likes