Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago

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

01minutesAfterMidnight = 0
02 
03while true do
04    minutesAfterMidnight = minutesAfterMidnight + 10
05    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
06    wait(0.1)
07 
08    if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 and minutesAfterMidnight < 17 * 59 then
09        if game.Workspace.SurfaceDay.IsPaused then
10        game.Workspace.SurfaceNight:Stop()
11        game.Workspace.SurfaceDay:Play()
12        end
13    end
14    if game.Lighting:GetMinutesAfterMidnight() > 18 * 00 and minutesAfterMidnight < 6 * 59 then
15        if game.Workspace.SurfaceNight.IsPaused then
16        game.Workspace.SurfaceDay:Stop()
17        game.Workspace.SurfaceNight:Play()
18        end
19    end
20end

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.

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. lightpower26 399 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This should work.

01minutesAfterMidnight = 0
02while true do
03    minutesAfterMidnight = minutesAfterMidnight + 10
04    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
05    wait(0.1)
06    print(minutesAfterMidnight)
07        if minutesAfterMidnight == 6*60 then
08            game.Workspace.SurfaceNight:Stop()
09            game.Workspace.SurfaceDay:Play()
10            end
11        if minutesAfterMidnight == 18*60 then
12            game.Workspace.SurfaceNight:Play()
13            game.Workspace.SurfaceDay:Stop()
14            minutesAfterMidnight = 0
15            end
16end
0
You can remove line 06, that was just for testing. Connor_1 3 — 8y
Ad

Answer this question