Calendar System not showing on TextLabel

So I’m trying to create a calendar system. Everything works fine except for making the calendar info connect to the text label. I’m not sure what I’m doing wrong but I know I’m doing something wrong.

The script is typed below and this is the only part that fails to work. It seems to stop at the “for _, thePlayers in pairs” section. I’ve tried it with just ‘player’, ‘players’, ‘Player’ and, ‘Players’, the same error arises. Feel free to ask more questions and I’ll try to answer them correctly.

local function waitForMidnight()
	while true do
		-- Wait till time is as close to Midnight
		repeat
			wait(1)		
			print("This is a test Message. This should show every 1 second(s).")
			
			for _, thePlayers in pairs(Players:GetPlayers()) do
				local thePlayersGUI = thePlayers:FindFirstChild("MainMenu_HUD")
				if thePlayersGUI then
					print("Found GUI")
					local PlayersGUI2 = thePlayersGUI:FindFirstChild("Core_Frame") and thePlayersGUI.Core_Frame:FindFirstChild("Date_Time_Weather")
					if PlayersGUI2 then
						print("Found GUI2")
						local CalendarText = playerGUI2:FindFirstChild("Day")
						print("Found Calendar")
						wait(1)
						if CalendarText then
							CalendarText.Text = dateText
							print("Updated Calendar with this current info: "..dateText".")
						end
					end
				end
			end
			
			
		until Lighting.ClockTime >= 23.99 or Lighting.ClockTime < 0.01
		updateDay()
		print(updateDay())
		wait(1) -- Small Delay to prevent multiple update intances
	end
end

Hi there. So to help you, we generally need the error or at least more info, such as which of the prints shows.
But I did a quick scan and at this segment, I noticed the following:

You declare PlayerGUI2
But where you declare CalendarText you use “playerGUI2” not “PlayersGUI2”, I think that might be the problem.
Let me know if this helps.

1 Like

I think you’re missing a level. The contents of StarterGui is put into PlayerGui within the player so you need to find that first before looking for your GUI.

local thePLayersGUI = ThePlayers:FindFirstChild("PlayerGui"):FindFirstChild("MainMenu_HUD")

Another way to do this is to add true to the end of your FindFIrstChild tag. This will search recursively within the player.

local thePLayersGUI = ThePlayers:FindFirstChild("MainMenu_HUD", true)

1 Like

Both responses yeilded the answer actually, two birds with one stone if you will. Sadly I never got an error warning prior, however after doing both adjustments Im now presented with this:

“Unable to assign property Text. string unexpected, got nil” in regards to “CalendarText.Text = dateText”.

dateText is coded as follows;

local dateText = string.format("Year %d, %s %d - %s", currentYear, season, currentDay, weekday)

The format looks fine but it will return nil if any of the parameters are nil. You can print the four parameters to see which one isn’t coming through or use the Watch view to see the values when the error happens.

1 Like

That’s perfect, yeah for some reason its having issue tying the week days table (Mon - Sun) and season (Spring - Winter) tables to the string.

Instead of Year 1, Spring, Day 1, Monday it’s Year 1, nil, Day 1, nil. Any ideas as to why that is? Either way thank you for sticking out and helping! :smiley: