Help needed with Script to play sound in day and sound at night (different sounds)

I’m trying to make it so a Day ambient sound will play when the Day cycle reaches morning and a Night Ambient sound to play when it reaches after sunset (Sounds and script are in the Bush part)
These are Forest Day and Night Ambient sound effects which will be played at night or day.

Sounds are not playing and there not delayed its just there not playing and its showing no error in the output

image

I’ve tried Playing.Enabled = true/false and I’ve tried :Play() but nothing worked

while true do
    wait(0.1)
    if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
        game.Workspace.Bush.DayForestAmbients.Playing.Enabled = true
        game.Workspace.Bush.NightForestAmbients.Playing.Enabled = false
    end
    print("sound1")
    if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
        game.Workspace.Bush.DayForestAmbients.Playing.Enabled = false
        game.Workspace.Bush.NightForestAmbients.Playing.Enabled = true
    end
end
1 Like
local lighting = game:GetService("Lighting")
local bush = workspace:WaitForChild("Bush")
local DFA = bush:WaitForChild("DayForestAmbients")
local NFA = bush:WaitForChild("NightForestAmbients")

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if lighting.ClockTime >= 6 and lighting.ClockTime < 18 then
		if NFA.IsPlaying then
			NFA:Stop()
		end
		if DFA.IsPlaying then
			return
		end
		DFA:Play()
	elseif lighting.ClockTime >= 18 or lighting.ClockTime < 6 then
		if DFA.IsPlaying then
			DFA:Stop()
		end
		if NFA.IsPlaying then
			return
		end
		NFA:Play()
	end
end)
1 Like

I recommended you to not write the entire code to them because they could just copy and paste, and then move on without understanding how the code works.

I think you’re getting a bit confused. There are two parts you need here that you don’t have.

First, you need to loop the sound you’re playing, which can be achieved with the line

game.Workspace.Bush.DayForestAmbients.Looped = true

Second, you need to play the sound itself, which can be achieved by using

game.Workspace.Bush.DayForestAmbients:Play()

Then you use your while loop to get minutes after midnight. if it’s past 6 pm, play night ambience and stop day ambience with

game.Workspace.Bush.DayForestAmbients:Stop()
game.Workspace.Bush.NightForestAmbients:Play()

and vice versa. All you need to do is edit your loop so you stop certain sounds and play other sounds. you do this using

:Play()

or

:Stop()

It’s pretty simple. You’ve got the right idea with the wrong execution.