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.

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.

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.

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

0
You can remove line 06, that was just for testing. Connor_1 3 — 8y
Ad

Answer this question