So I recently got this script for a very kind and helpful person, but I have no clue as to how to put this into a text box and make it show up with the time, any help? Here is the script.
local Lighting = game:GetService("Lighting")
local hourRaw = tonumber(Lighting.TimeOfDay:match("^%d+"))
local hour12h = math.floor(hourRaw % 12)
local isPM = (hour / 12) >= 1
if hour12h == 0 then
hour12h = 12
end
Now, the only issue im having here is, for my game, I have it set up so that its a build up knowning, when the next time is, any way to add minutes to that? Also, its stuck at 2pm?
Most likely because you did not add it into a loop of some sort and just copy-pasted the code into the script. This is a relatively primitive situation which you could fix by adding this in yourself as opposed to relying only on code I post. I don’t provide whole scripts to use, I provide segments that you need to modify to work for your use cases.
I tried this, and it timed out, should I add a wait of a second or 2?
local Lighting = game:GetService("Lighting")
while true do
local hourRaw = tonumber(Lighting.TimeOfDay:match("^%d+"))
local hour12h = math.floor(hourRaw % 12)
local isPM = (hourRaw / 12) >= 1
if hour12h == 0 then
hour12h = 12
end
local formattedTime = ("%d:%d %s"):format(hour12h, "00", isPM and "PM" or "AM")
script.Parent.TextLabel.Text = formattedTime
end
Again, something else you could figure out on your own without me telling you. The script times out because your while loop doesn’t have a wait in it. Luckily, timeout behaviour does exist, because regularly this would have crashed Studio.
Yes, you should add a wait at the end of the loop.