Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why doesn't my time script work?

Asked by
Sam4550 42
10 years ago

Basically, I have a ScreenGUI and there's a clock and a date display on it. Whenever I open up my Test, it says on line 51 "Error - Attempt to concatenate local 'weekday' (a nil value)". What's wrong?

This is the script:

local t = tick()
local year = 2000
local month = 1
local day = 1
local Date = "2000.01.01-Sa"
local hour = 0
local mint = 0
local sec = 0
local Time = "00:00:00"
local weekdays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}

function getDateTime()
    local months = {
        {"01",31,31};
        {"02",59,28};
        {"03",90,31};
        {"04",120,30};
        {"05",151,31};
        {"06",181,30};
        {"07",212,31};
        {"08",243,31};
        {"09",273,30};
        {"10",304,31};
        {"11",334,30};
        {"12",365,31};
    }
    local daycount = math.floor(t/86400)-10957
    local weekdaynumber = daycount%7
    local weekday = weekdays[weekdaynumber]
    year = math.floor(daycount/365.25)+2000
    if ((year%4) == 0) then
        months[2][3] = 29
        for i,v in pairs(months) do
            if (i ~= 1) then
                v[2] = (v[2]+1)
            end
        end
    end
    day = math.floor(((daycount)%365.25)+1)
    for i,m in pairs(months) do
        if ((m[2]-m[3]) <= day) then
            month = i
        end
    end
    local m = months[month]
    day = (day+m[3]-m[2])
    year = tostring(year)
    local days = day
    days = tostring((days < 10 and "0" or "") .. days)
    local mnth = months[month][1]
    Date = (year .. "." .. mnth .. "." .. days .. "-" .. weekday)
    local sec = math.floor((t%60))
    local mint = math.floor((t/60)%60)
    local hour = math.floor((t/3600)%24)
    sec = tostring((sec < 10 and "0" or "") .. sec)
    mint = tostring((mint < 10 and "0" or "") .. mint)
    hour = tostring((hour < 10 and "0" or "") .. hour)
    local seconds = (t%60)
    Time = (hour .. ":" .. mint .. ":" .. sec)
end

function display(start)
    if (start) then
        getDateTime()
    end
    script.Parent.Time.Text = Time
    script.Parent.Date.Text = Date
end

function start()
    display(true)
    while (true) do
        t = tick()
        getDateTime()
        display()
        wait()
    end
end

start()

1 answer

Log in to vote
0
Answered by
jacobwow 140
10 years ago

I may be wrong but in the script line 10 it says weekdays and in line 51 it says weekday. I think you should try making it weekdays on line 51

Ad

Answer this question