Hi there, I have a script that cycles through the day but I wanted to play ambience depending on the time of day, if it’s in the morning then birds singing, if it’s at night then crickets chirping and wind hustling etc.
Doesn’t have to be complex like sounds for each hour of the day or anything crazy, just a suggestion on how to do 1 for day and 1 for night would be great!
It’d be nice to have the code cuz I’m lazy but implement this:
local day = false -- outside of the function
local nightmusic = "soundlink"
local daymusic = "soundlink"
somewhere inside the while loop add
if L.ClockTime > 18 and day == true then
day = false
spawn(function()
repeat task.wait(.1) daymusic.Volume += -.1 until daymusic.Volume <= 0
daymusic:Stop()
daymusic.Volume = 1 -- or reset it to what it was before
task.wait(.5) -- give it another sec
nightmusic:Play()
end)
elseif L.ClockTime > 6 and day == false then
day = true
spawn(function()
repeat task.wait(.1) nightmusic.Volume += -.1 until nightmusic.Volume <= 0
nightmusic:Stop()
nightmusic.Volume = 1 -- or reset it to what it was before
task.wait(.5) -- give it another sec
daymusic:Play()
end)
end
You may want to add :Stops to the music that shouldn’t be playing.
@ Joel I’d also suggest using a loop to decrease the day sound volume when it changes and increase the night sound volume so you don’t get a sudden switch.
You don’t need to use the Cycle function, just use your while true do loop.
You should add a task.wait(5) or a WaitForChild for Lighting at the beginning just to make sure Lighting is loaded in case of a bit of lag.
I assume their goal is to make it look as smooth as possible.
Depending on the type of game it is, it shouldn’t be a big deal. Also .1 is a pretty generous wait time believe it or not. I think it’d be more ideal to create a client script that uses heartbeat and attach all client related code that will be looped to it generally through modules though I’m only providing the answer to his question, not re-scripting his game.
@Scottifly Yeah adding :Stop() is kind of important whoops I’ll edit that. I’ll also add a fade for him if he wants that. You would only need to check if its loading still if it is being run on the client (which it should be) but my guess is that it isn’t.
Oh yeah, don’t forget to set your ambient sounds to Looped so they keep playing instead of stopping after the first time through.
Make sure the sounds actually loop smoothly without a sudden change that would make it annoying to hear the transition at the end/beginning of each loop.
and add a fade to it what is that option called…crossfade or something…
then add some zoneplus zones to see what time of day or night music to play… like jungle… city, forest… etc…
then create a plugin that combines that all, and loadeds different sky boxes and lighting effects depending on time of day and zone…
then have it so you can play different sounds on the same night or day… like a 2nd sound wolf howl at the begging of night, and a 2nd sound rooster at the break of dawn…