Days of the week script

So, i’m currently trying to make a time and date script for game, but the date script isn’t working. It doesn’t change at all though, I was wondering if I could get some help with it.

Heres the script:

local Days = {
-- The days of the week would go inside of this table as strings
}
local text = script.Parent

while true do
wait(1)
for i = 1, #Days do
     local CurrentDay = Days[i]
     text.Text = CurrentDay
     repeat wait(1) until game.Lighting.ClockTime == 24
     -- I want the loop to run again when the time hits 24 or 12 AM
end
end

Could this work for what you’re trying to do?

Nope, already looked. Its too complicated and I want to use tables anyway.

like this?

local Days = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"}
local data = os.date("%a")

local text = script.Parent

while true do
   wait(1)
   text.Text = data
end
1 Like

or like this

local function formatDay(day: number)
    local days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}

    return days[day % 7 ~= 0 and day % 7 or 7]
end

print(formatDay(14)) --> Sunday

Here, use this:

You want to use DateTime.now():ToUniversalTime()

What I would do is check whenever the time changes and see if it has passed midnight, then change the day. I also would do that on the server and utilize a StringValue in ReplicatedStorage so clients can read off of that. Here is what this code would look like:

-- Services --

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")

-- Variables --

local CurrentDay = 1
local DayValue = ReplicatedStorage:WaitForChild("CurrentDay")
local LastTime = Lighting.ClockTime

-- Tables --

local Days = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"}

-- Scripting --

Lighting.Changed:Connect(function()
	local CurrentTime = Lighting.ClockTime
	if LastTime > CurrentTime then
		CurrentDay += 1
		if CurrentDay > 7 then
			CurrentDay = 1
		end
		DayValue.Value = Days[CurrentDay]
	end
	LastTime = CurrentTime
end)

This produces the following result:
https://gyazo.com/31fe4ea426a0bf76b3fde50b65d1332f

With this method, you can adjust time however you like and it will always function (you can slow down or speed up time and it will work just fine).

You can also examine the place itself here:
TimeDayDemo.rbxl (37.6 KB)

I hope this helped.

6 Likes

Oh thanks! I didn’t know Lighting.Changed was an RBXScriptSignal.