Day/Night Counter GUI

Hello! I am having a lot of trouble trying to make this function for my game. I looked around and only found one other dev forum post on this topic, however it did not work for me.

I need help making it so whenever night time begins, a GUI at the top of the screen changes its text. For example, Night 1, Night 2, etc. I will attach some images below, thanks!


DayNightGUI

Beginning of Daytime is “6:00:00”
Beginning of Night is “18:00:00”

I don’t need the text to count the number of days, only nights. During the day the text will just say “Day.”

1 Like

do an if statement to detect if it’s night time. If it is not then change the text to “day”

local lighting = game.Lighting
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if lighting.ClockTime >= 6 and lighting.ClockTime < 18 then
		print("It's day!")
	end
end)

Test the code and whenever the clock changes to day it will print It’s Day

how would it count the amount of nights that pass though?

local lighting = game.Lighting
local Nights = 0

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if lighting.ClockTime == 6 then
		Nights = Nights + 1
script.Parent.Text = "Night "..Nights
elseif lighting.ClockTime == 18 then
script.Parent.Text = "Day"
	end
end)

Where it says “TEXT THING HERE” you put the Text

If you want to count the total amount of nights that pass the code would be a little more complicated.

local lighting = game.Lighting
local debounce = false
local TotalNightsPassed = 0

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if lighting.ClockTime >= 6 and lighting.ClockTime < 18 then
		debounce = false
	elseif debounce == false then
		debounce = true
		TotalNightsPassed = TotalNightsPassed + 1
		script.Parent.Text = "Nights " .. TotalNightsPassed
	end
end)

The code should work directly into the script if u copy/paste

1 Like

@CrispyTRCS I scripted this so that you can just insert it directly into the game

Thanks so much it helped a lot! :slight_smile:

1 Like

Thank you so much I have been trying to get this for so long lol. Appreciate it alot :+1:

Would appreciate it if you mark my post as the Solution and yw! :slight_smile: