Moon Cycle System [v1.1]


About:

The Moon Cycle is a system that uses a day and night cycle and waits every 3 in-game days to change its moon into the next phase. It starts off as a new moon and then continues its moon cycle from there. It will change its phase at the beginning of each 3 days

How The Script Works

The script works by waiting for the ClockTime in Lighting to hit 6, meaning a new day has started. It will then add +1 to a value in ReplicatedStorage called MoonPhase. Once the MoonPhase hits a certain number it will change the MoonTextureId to its next phase at the beginning of the new day. Once the MoonPhase hits value 21 it will reset back to zero.

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if Lighting.ClockTime == 6 then
		MoonPhase.Value += 1
		if MoonPhase.Value == 0 then --Waxing Crescent
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095157365"
		elseif MoonPhase.Value == 3 then --First Quarter
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095158174"
		elseif MoonPhase.Value == 6 then --Waxing Gibbous
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095158894"
		elseif MoonPhase.Value == 9 then --Full Moon
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095160877"
		elseif MoonPhase.Value == 12 then --Waning Gibbous
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095161662"
		elseif MoonPhase.Value == 15 then --Third Quarter
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095163367"
		elseif MoonPhase.Value == 18 then --Waning Crescent
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8095165702"
		elseif MoonPhase.Value == 21 then --New Moon
			Skybox.MoonTextureId = "http://www.roblox.com/asset/?id=8107271297"
			MoonPhase.Value = 0
		end
		print(MoonPhase.Value)
	end	
end)
Phases

Moon Cycle:
image

New Moon:
New Moon Redesign

Waxing Crescent:
Waxing Crescent

First Quarter:
First Quarter

Waxing Gibbous:
Waxing Gibbous

Full Moon:
Full

Waning Gibbous:
Waning Gibbous

Third Qaurter:
Third Qaurter

Waning Crescent:
Waning Crescent

Future Updates

A lot is planned to be added in the future for the moon cycle such as:

  • Celestial Events - Ex: Solar Eclipse, Lunar Moon, Blood Moon, meteor showers
  • Moon Gui - shows what phase the moon is on, what time of the day it is, and what the weather is like.
  • Weather System

If anyone has any suggestions they want to add I will gladly add them in and credit you for the suggestion.

Model Demo:
https://www.roblox.com/library/8108400155/

Game Demo:
roblox.com/games/8108587773/Moon-Cycle-Test

36 Likes

Cool project! However, I don’t think you needed that many if statements. You could just make a dictionary indexed by numbers and loop through it. I guess you could do something like this:

local phases = {
[0] = "rbxassetid/####"
}

Other than that, it looks fantastic!

5 Likes

I plan to make the script easier to edit for those who don’t know how to script or don’t know how the script works.

1 Like

Update V1.1

Update Log:

  • Improved, and more simple script.
  • Moon Gui Added!
Scripts

Credit to @LuaPrime8 for the idea of improving the script!

Moon phases Script:

local MoonPhase = game.ReplicatedStorage.MoonPhase
local Lighting = game:GetService("Lighting")
local Skybox = Lighting.Sky

local Phases = {
	[0] = "http://www.roblox.com/asset/?id=8095157365", --Waxing Crescent
	[3] = "http://www.roblox.com/asset/?id=8095158174", --First Quarter
	[6] = "http://www.roblox.com/asset/?id=8095158894", --Waxing Gibbous
	[9] = "http://www.roblox.com/asset/?id=8095160877", --
	[12] = "http://www.roblox.com/asset/?id=8095161662", --Waning Gibbous
	[15] = "http://www.roblox.com/asset/?id=8095163367", --Third Quarter
	[18] = "http://www.roblox.com/asset/?id=8095165702", --Waning Crescent
	[21] = "http://www.roblox.com/asset/?id=8107271297", --New Moon
}

if script.MoonCycle.Value == true then
	print("MoonCycle Is enabled")
	Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
		if Lighting.ClockTime == 6 then
			MoonPhase.Value += 1
			for value, Phase in pairs(Phases)do
				if MoonPhase.Value >= 24 then
					Skybox.MoonTextureId = Phases[0]
					MoonPhase.Value = 0
				elseif MoonPhase.Value == value then
					Skybox.MoonTextureId = Phase
				end
			end
			print(MoonPhase.Value)
		end
	end)
else
	print("Mooncycle is Disabled")
end

Forecast Script:

local MoonPhase = game.ReplicatedStorage.MoonPhase
local Lighting = game:GetService("Lighting")

MoonPhase.Changed:Connect(function()
	if MoonPhase.Value == 0 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109761760"
		script.Parent.MoonPhase.Text = "Waning Crescent"
	elseif MoonPhase.Value == 3  then
		script.Parent.ImageLabel.Image = "rbxassetid://8109763261"
		script.Parent.MoonPhase.Text = "First Quarter"
	elseif MoonPhase.Value == 6 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109764660"
		script.Parent.MoonPhase.Text = "Waxing Gibbous"
	elseif MoonPhase.Value == 9 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109766530"
		script.Parent.MoonPhase.Text = "Full Moon"
	elseif MoonPhase.Value == 12 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109770374"
		script.Parent.MoonPhase.Text = "Waning Gibbous"
	elseif MoonPhase.Value == 15 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109772223"
		script.Parent.MoonPhase.Text = "Third Quarter"
	elseif MoonPhase.Value == 18 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109773184"
		script.Parent.MoonPhase.Text = "Waning Crescent"
	elseif MoonPhase.Value == 21 then
		script.Parent.ImageLabel.Image = "rbxassetid://8109775155"
		script.Parent.MoonPhase.Text = "New Moon"
	end
end)

Lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()
	local Hours = tonumber(string.sub(Lighting.TimeOfDay, 1, 2)) -- Gets the hours, turns 05 --> 5
	local Minutes = string.sub(Lighting.TimeOfDay, 4, 5) -- Gets the minutes, keeps the extra 0

	local String = '%s:%s %s'

	if Lighting.ClockTime >= 13 and Lighting ~= 0 then -- It's between 1pm and 11:59pm
		String = String:format(Hours - 12, Minutes, 'pm')
	elseif Lighting.ClockTime >= 12 and Lighting.ClockTime < 13 then -- It's between 12pm and 12:59pm
		String = String:format(Hours, Minutes, 'pm')
	elseif Lighting.ClockTime >= 0 and Lighting.ClockTime < 1 then -- It's between 12:00am and 12:59am
		String = String:format(12, Minutes, 'am')
	else -- It's between 1:00am and 11:59 am
		String = String:format(Hours, Minutes, 'am')
	end

	script.Parent.Time.Text = String
end)

If you wish to change the when the moon phases occur then change the numbers in the table called Phases
and change the number in if MoonPhase.Value >= 24 then to the number of in-game days you want it to take to complete a full moon cycle. Currently, its default is 24 in-game days for a whole moon cycle to finish. But please note that every moon phase needs to be a different number, the phases at top of the table need to be the lowest numbers, and the phases at the bottom of the table need to be the highest numbers in the table.

If you wish to replace the texture of a moon phase then replace the texture in between the " " in the table and you’re pretty much done.

I would also recommend not editing certain parts of the script minus the values unless you know what you’re doing. I hope y’all have a great day, night, or whatever time it is for y’all! The new updates can be found both in the model demo, and game demo.

4 Likes

hey this seems cool but will it work if i have a day and night script that works like 5 a day and 5 mins a night

1 Like

I know, it’s set as a minute for day and night for demonstration ok how it works so everyone doesn’t have to wait 5 minutes per night and day to see change

1 Like

Here’s a preview of the rain weather during a waxing crescent

3 Likes