Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I made easy time GUI but how do I erase miliseconds?

I did easiest time GUI ever with Day/Night cycle using TimeOfDay which is "xx:xx:xx" I tried to remove miliseconds in time GUI using :gsub(), but it ALSO removes normal seconds when they reach :00. There is script

local Time = script.Parent
while true do
Time.Text = game.Lighting.TimeOfDay
Time.Text = Time.Text:gsub(":00","")
wait(0.1)
end

Soo, how I can stop it from deleting seconds and delete only miliseconds? Is there a way to check?

2 answers

✓ Accepted answer

Another option is to use string.split(string, character).

This returns a table of each split, then you can just get the first 2 and ignore milliseconds.

local Time = script.Parent
while true do
local timeOfDay = tostring(game.Lighting.TimeOfDay):split(":");
Time.Text = timeOfDay[1]..":"..timeOfDay[2];
wait(0.1)
end

Usually to get the in-game time I use string.sub() allows me to even create variables for hours/minutes/seconds. There's no miliseconds.

If you want to keep everything but the seconds, just do

local timeOfDay = game.Lighting.TimeOfDay
Time.Text = string.sub(timeOfDay, 1, 5) -- Format: 00:00

Instead of using a loop, you can instead connect to the event LightingChanged which fires whenever the lighting's properties are changed or GetPropertyChangedSignal("TimeOfDay") to call your function whenever the TimeOfDay changes.

Example with GetPropertySignalChanged

game.Lighting:GetPropertySignalChanged("TimeOfDay"):Connect(function()
	-- your code
end)

Example with LightingChanged

game.Lighting.LightingChanged:Connect(function() 
	-- your code
end)

Related documentation: string, GetPropertyChangedSignal(), LightingChanged

1 comment

0

GetPropertyChangedSignal doesn't loops, changes only once

This discussion is preserved as it was. New answers, comments, and votes are closed.