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

Time of day, different song every 12 hour in game issue?

Asked by
Kryptio 19
7 years ago
Edited 7 years ago

So im having another scripting issue... I have two songs that i would like to be played but at different times, one at 6am and the other at 6pm and this method works fine until it reaches 6pm again. Not sure what im doing wrong on this..

local Song = game.Workspace.PalletTown1.Dakota
local Song1 = game.Workspace.PalletTown1.Dakota1

while true do
    wait(.1)

    if game.Lighting.TimeOfDay == "06:00:00"
        then 
        Song1:Stop ()
        wait(.1)
        Song:Play()
        Song.Looped = true
    print("Day Song is playing")
    end
    if game.Lighting.TimeOfDay == "18:00:00"
        then 
        Song:Stop ()
        wait(0.1)
        Song1: Play()
        Song1.Looped = true
    print("Night Song is playing")

    end
end

1 answer

Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
7 years ago
Edited 7 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
Song = game.Workspace.PalletTown1.Dakota
Song1 = game.Workspace.PalletTown1.Dakota1
minutesAfterMidnight = 0

while true do
    -- remove these lines if you don't want a new day/night cycle.
    minutesAfterMidnight = minutesAfterMidnight + 1 -- Speed of the day/night cycle. Remove 
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(0.1)  
    -- This basically takes whatever time it is in the game, and constantly adds one to the time every 0.1 seconds, as the while true do loop constantly keeps it running. And starts over once finished.


    if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then -- checks for 6AM
        Song1:Stop()
        wait(.1)
        Song:Play()
        Song.Looped = true
        print("Day song playing.")
    end
    if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then      -- checks for 6PM
        Song:Stop()
        wait(.1)
        Song1:Play()
        Song.Looped = true
        print("Night song playing.")
    end
end

The while true do is an event which constantly runs any code between it, over and over until there is a break. The first if statement is constantly called to check when it is 6 AM, once that is true it runs any code after it until it ends. The second if statement is constantly called to check for when it is 6 PM, once that is true, it runs the code after it. If you wish not to have a day/night cycle, remove the first 3 lines of code underneath the while true do

Hope this helps!

0
wouldnt this create a new Day/Night Cycle? If so i already have on in a separate script. I wouldnt be able to combine them like this bec my game will have separate area in the game. Kryptio 19 — 7y
0
Are you able to just use this script? Or not? awfulszn 394 — 7y
0
You have to be able to explain the script for him to understand it. Shawnyg 4330 — 7y
0
To prevent it from making a new day/night cycle, just remove the first 3 lines under the 'while true do'. awfulszn 394 — 7y
View all comments (3 more)
0
probably not bec when my players go to a different area it will have a different music for that area. Which is why i had my day cycle code in another script, if i did it this way it would make 2 day cycles and cause an error. Basically what im focusing on is if your in this town it will start off in the day song then once night hit i would want the night time song to play, but i wouldnt want thi Kryptio 19 — 7y
0
Just remove the 3 lines of code underneath the 'while true do'. awfulszn 394 — 7y
0
this song for another town or a route bec then it would be too plain. Thats why i had the TimeOfDay function instead of SetMinutesAfterMidnight Kryptio 19 — 7y
Ad

Answer this question