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

How do I get day of the week using os.date() ?

I want special things to happen in my game during a certain day of the week, I've researched a bit and I found command os.date() which creates a table of information about current time, but... I don't really know how to read from arrays/tables. If I run this command

for k, v in pairs(os.date("*t")) do print(k .. ": " .. v) end

i get in output:

-- x is a number of hrs, mins, secs...

hour: x
min: x
wday: x
day: x
month: x
year: x
sec: x
yday: x

Now I want to get number of "wday", and if it's for an example 2, script would print "It's Monday!" So this is basically a question about how to read tables...

1 answer

✓ Accepted answer

Its quite simple. Lets say you wanted to set a IntValue to the day of the week you would do something like this!

local tab = os.date("*t") -- Getting the array.
local value = Instance.new("IntValue",workspace) -- Making the value and parenting it.
value.Name = "DayOfWeek" -- Naming the value
value.Value = tab.wday -- Changing the value
print(value.Value) -- Make sure it works!

1 comment

0

Thank you so much, I actually want to use !*t instead of *t

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