A script about a month changing system

46 views Asked by At

Im trying to change the number of visible textlabels when the month has changed but it doesnt change it only stays at the first month that was stated and doesnt change the number of visible textlabels based on the month/days of months

local player = game.Players.LocalPlayer
local PlayerGUI = player.PlayerGui
local Window = PlayerGUI.Computer.Window
local DateWindow = Window.CalenderWindow
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DateNumbers = DateWindow.DaysHandler:GetChildren()

local DaysInMonth = {
    January = 31,
    February = 28,
    March = 31,
    April = 30,
    May = 31,
    June = 30,
    July = 31,
    August = 31,
    September = 30,
    October = 31,
    November = 30,
    December = 31
}

local Months = ReplicatedStorage.Months:GetChildren()
local CurrentMonth = ReplicatedStorage.CurrentMonth.Value
local monthSwitched = false

for _, DayLabel in pairs(DateNumbers) do
    local dayNumber = tonumber(DayLabel.Name)

    if not monthSwitched and dayNumber > DaysInMonth[CurrentMonth] then
        for _, month in pairs(Months) do
            local daysInCurrentMonth = DaysInMonth[month.Name]
            CurrentMonth = month.Name
            monthSwitched = true
            break
        end
    end

    if dayNumber <= DaysInMonth[CurrentMonth] then
        DayLabel.Visible = true
    else
        DayLabel.Visible = false
    end
end

I tried Using another forloop to try getting the months folder and use that as the current month but it didnt seem to work out.

1

There are 1 answers

0
user15611379 On

local tab={
    January = 31,
    February = 28,
    March = 31,
    April = 30,
    May = 31,
    June = 30,
    July = 31,
    August = 31,
    September = 30,
    October = 31,
    November = 30,
    December = 31
}
local labels=player.PlayerGui.Computer.Window.CalenderWindow.DaysHandler:GetChildren()
game.ReplicatedStorage.CurrentMonth.Changed:Connect(function(i)
    for _,label in(labels)do 
        label.Visible=tonumber(label.Name)<=tab[i]
    end
end)
local i=game.ReplicatedStorage.CurrentMonth.Value
for _,label in(labels)do 
    label.Visible=tonumber(label.Name)<=tab[i]
end