I already have the day/night cycle script done, but I would like to know how to make different music play when the clocktime reaches a certain time. For example, when the ClockTime reaches, say, 6.2, the background music will change from what it was initially. I am wanting this process to loop. Hopefully this is enough info. I literally have no idea how to do this :/
How to make different music play at day and at night?
2 answers
"I literally have no idea how to do this" That doesn't mean you can't post an attempt man. You got to at least try it. Even if it doesn't come out great that is the point of the site. To help people with code that is not working as they wish.
However I will go ahead and point you in the right direction.
Make use of the Lighting.LightingChanged event. It fires when the skybox changes, or when some property related to the lighting is changed.
I don't think you need to change a skybox for this so I'll just return out of the function if skybox was changed
local Lighting = game:GetService("Lighting")
Lighting.LightingChanged:Connect(function(skybox_changed)
if skybox_changed then
print("Skybox change so not doing anything")
return
end
end)
Hello there, this is Tizzel here lol <:D>!
Its been a long time since ive been on scripting helpers, so you will be my first person to be helped by me lol! <:D>!
So I heard that you want music to play depending on the time of day!
so First insert a script in ServerScriptService.
so Now, we will write!
`game.Players.PlayerAdded:Connect(function(plr)
--------------Settings///-------
local StillMorningTime = false---I Made these Two Variables so we can tell if is still morning
local StilNightTime = false--------I Made these Two Variables so we can tell if is still Night
-----------
local MorningTime_Music = "rbxassetid://000"--Please Place you Id Right Here!!! (Take Out 000)
local NightTime_Music = "rbxassetid://000"--Please Place you Id Right Here!!! (Take Out 000)
local NightTime = 18----Its Night time! (Yawn - Nighty Night!) <:3
local MorningTime = 6----Its Morning! (Yawn)! :3
-----------------------------------------------------------------------------
local Lighting = game.Lighting----Get the Lighting then....
local Music = Instance.new("Sound")--Create the Music Value
Music.Name = "Music"---Name it whatever you want
Music.Volume = 1.5----Put the Volume to whatever you want!
Music.Looped = true----Set this to true or false (I recomend true though!)
Music.Parent = plr:WaitForChild("PlayerGui")
----Note: Masic Math/Comparisions Required to do this lol! (Below)!
local function OnCheckForTime()---Create A Function to check what time it is, then if its morning or night, a specific song will Play! <:D>!
if Lighting.ClockTime >= MorningTime and Lighting.ClockTime < NightTime then---If the CLock time is Higher or equal to the morning time and less
----than the NightTime Variable then...
if not StillMorningTime then---If it has already turned morning (because we dont want the music to keep restarting over and over agin!)
StillMorningTime = true-----Make it true
StilNightTime = false---Make this false (Because it is simpley not night time!)
Music.SoundId = MorningTime_Music---Make the Sound Id the Morning Music Variable (Which is the Id)
Music:Play()
end
elseif Lighting.ClockTime >= NightTime or Lighting.ClockTime < MorningTime then----Else if the Clock time "Exceeds" the Nightime Number which is 18 or its lower than the Morning time then lol......
if not StilNightTime then----If its not Alredy NIghtime then...
StilNightTime = true---Make this true
StillMorningTime = false----Make this false because it simpley not Morning time anymore!
Music.SoundId = NightTime_Music-----Make the Id the Night time music now this time! <:D>!
Music:Play()---Now Play It!
end
end
end
OnCheckForTime()---CHeck for time As Soon As you enter the game! <:D>!
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(OnCheckForTime)----And then now check for the time Every time the "CLockTIme" Value has been changed in lighting!!!
end)`
And That is how we get a good working Music Script for Day and Night Cycles Lol!
Please Don't sit there and just copy all this work, and learn nothing from it! That's why I literally spent 35 Minuets on writing this whole script from scratch and answering your question, even with added comments to help you guide you right along through the whole entire script!
Once you get this whole Script down, I want you to go Play and test you game and Click the "Current Client" Button in the Test Tab above and now you in the "Current Server"!
Once you are the , go to the lighting in the Explore, then in you properties, look for the Clock Time. Go and switch the Numbers up and Play around a bit and see if you music changes whether if is daylight or not lol! <:D>!
Alright, I Guess that's enough rambling from me lol! Have fun and never give up!!
Have a Good Day Quinzt! <:D>!
---by T40!, 2019!
---<:D>!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
P.D. this is not meant to be full working code