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

How do I make different music play at daytime and nighttime correctly?

So I have two Background Music files in the workspace called "SurfaceDay" and "SurfaceNight." I use this script down below.

minutesAfterMidnight = 0

while true do
	minutesAfterMidnight = minutesAfterMidnight + 10
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(0.1)
	
	if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 and minutesAfterMidnight < 17 * 59 then
		if game.Workspace.SurfaceDay.IsPaused then
		game.Workspace.SurfaceNight:Stop()
		game.Workspace.SurfaceDay:Play()
		end
	end
	if game.Lighting:GetMinutesAfterMidnight() > 18 * 00 and minutesAfterMidnight < 6 * 59 then
		if game.Workspace.SurfaceNight.IsPaused then
		game.Workspace.SurfaceDay:Stop()
		game.Workspace.SurfaceNight:Play()
		end
	end
end

The problem here is that if the time was nighttime, the Night music only plays once when I set it to loop, and if the time was daytime, the Day music played but the Night music never plays. Is there a reason for this problem and how do I fix this?

Thank you.

1 comment

0

Get rid of the line that says the other music "IsPaused" for two reasons: 1. I don't see any reason to have it there and 2. IsPaused and basically anything else that detects if the sound has stopped playing is broken.

1 answer

This should work.

minutesAfterMidnight = 0
while true do
    minutesAfterMidnight = minutesAfterMidnight + 10
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(0.1)
	print(minutesAfterMidnight)
    	if minutesAfterMidnight == 6*60 then
        	game.Workspace.SurfaceNight:Stop()
        	game.Workspace.SurfaceDay:Play()
        	end
		if minutesAfterMidnight == 18*60 then
        	game.Workspace.SurfaceNight:Play()
        	game.Workspace.SurfaceDay:Stop()
			minutesAfterMidnight = 0
        	end
end

1 comment

0

You can remove line 06, that was just for testing.

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