Day and night music not working

Hi dev’s!

I found in my inventory day and night music script and paste in game:

while true do
	if game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime <= 18 then
		game.Workspace.Sound.Atmosphere.Day:Play()
		game.Workspace.Sound.Atmosphere.Night:Stop()
	end
	if game.Lighting.ClockTime >= 18 or game.Lighting.ClockTime <= 6 then
		game.Workspace.Sound.Atmosphere.Day:Stop()
		game.Workspace.Sound.Atmosphere.Night:Play()
	end
	wait(0.1)
end

But its not worked.

Have a nice day!

1 Like

Is this a local or server script?

1 Like

Change the location of your sounds and call this using a local script in StarterGui, it should work.

local SoundService = game:GetService("SoundService")

while task.wait(1) do
	local clockTime = game.Lighting.ClockTime

	if clockTime >= 6 and clockTime < 18 then
		SoundService.Atmosphere.Day:Play() 
		workspace.Sound.Atmosphere.Night:Stop() -- move to SoundService like the first
	else
		workspace.Atmosphere.Day:Stop() -- move to SoundService like the first
		workspace.Sound.Atmosphere.Night:Play() -- move to SoundService like the first
	end
end

2 Likes

Sound starts but cannot continue and then starts again

1 Like

proof:

1 Like

You want it to be played only one time or in a loop?

1 Like

Sound actually in the loop. I dont know where problem.

1 Like

The loop is the problem, it will keep playing again and again, this should fix your problem.

local SoundService = game:GetService("SoundService")

while true do
    local clockTime = game.Lighting.ClockTime

    if clockTime >= 6 and clockTime < 18 then
        if not DaySound.IsPlaying then
            DaySound:Play()
        end
        if NightSound.IsPlaying then
            NightSound:Stop()
        end
    else
        if DaySound.IsPlaying then
            DaySound:Stop()
        end
        if not NightSound.IsPlaying then
            NightSound:Play()
        end
    end

    task.wait(1)
end





2 Likes

thank uuuuuuuuuuuuuuuuuuuuuuuuu

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.