Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a sound stop playing at night, and start at day time?

How do I make a sound stop playing at night, and start at day time? I'm trying to make birds sing at day, but not at night. It seems simple, but I can't find a solution.

1 answer

✓ Accepted answer

To do this, I am guessing you have a day / night cycle script using ClockTime in the game. Try this:

local sound = [Locate your sound here]
if game.Lighting.ClockTime >= 18 then
	sound:Stop()
	else 
	if game.Lighting.ClockTime >= 7  and game.Lighting.Clockdown <= 17 then
	sound:Play()
end
end

[I did this from what I think, should work. So pls let me know if it wont work. {Try removing <= 17}. Also, if the time goes above 24 this will allways work as night]

12 comments

0

Thanks, where should I put this script? I'll let you know if it works.

0

The script should work in server script service. But in my oppinion, it will be best in Lighting. You can then replace game.Lighting with script.Parent [If you put it DIRECTLY under lighting.]

0

I'm sorry for this, but how should I locate this? I know it's like SoundService.parent.script or something like that, but I'm really new to scripting ????

0

Locate the script, or the sound?

0

local sound = [Locate your sound here] the sound.

0

I think I got it, I will test.

0

yes, So if you have the soung in Sound Sevice. It will be game.SoundService.[SoundName], or if you have it in workspace as a model. It will be workspace.[ModelName].[SoundName] -- Feel free to ask anything else!

0

Okay i still hear it playing after 17 i will try see if the day night cycle is causing the problem.

0

I don't have the most used day/night cycle script but I have one where to ambient changes too, can this be a problem?

0

Is the day / night cycle a local script, or server sided script? [Any changes u do on a LOCAL script will be that client only]. So since this is made for a normal 'script', if the day / night script is local [client sided] this can break. Try changing them both to local scripts / normal scripts!

0

Both of them are normal scripts, day/night cycle is in workspace, the script you gave me is in ServerScriptService. I tried turning both to LocalScript but now the day/night cycle doesn't work.

0

K, revert them to normal scripts. Server sided. I was looking through things and found this: https://devforum.roblox.com/t/help-with-music-change-at-night-script/259657/2. This might help, but idk.

This discussion is preserved as it was. New answers, comments, and votes are closed.