Answered by
2 years ago Edited 2 years ago
EDIT:
I thought of a new solution. Instead of using a loop, let's just use the signal that detects whenever the ClockTime is changed.
01 | local sound = workspace.Sound |
02 | local sleepsound = workspace.SleepSound |
03 | local Lighting = game:GetService( "Lighting" ) |
06 | local startOfNight = 18 |
08 | script:SetAttribute( "Daytime" , true ) |
09 | script:GetAttributeChangedSignal( "Daytime" ):Connect( function () |
10 | local attribute = script:GetAttribute( "Daytime" ) |
11 | if attribute = = true then |
20 | Lighting:GetPropertyChangedSignal( "ClockTime" ):Connect( function () |
21 | local clockTime = Lighting.ClockTime |
23 | if (clockTime > = startOfDay) and (clockTime < startOfNight) then |
24 | script:SetAttribute( "Daytime" , true ) |
25 | elseif (clockTime > = startOfNight) or (clockTime < startOfDay) then |
26 | script:SetAttribute( "Daytime" , false ) |
OLD:
I recommend use BoolValues or Attributes. Attributes are basically custom "properties" you can make in Instances. When it's day, you make the Attribute true, and false when it's night. Then, when the attribute changes, connect Instance:GetAttributeChangedSignal()
signal to a function where it plays a music whether it's day or night.
01 | local sound = game.Workspace:WaitForChild( "Sound" ) |
02 | local sleepsound = game.Workspace:WaitForChild( "SleepSound" ) |
03 | local timer = game:GetService( "Lighting" ) |
05 | script:SetAttribute( "Daytime" , true ) |
06 | script:GetAttributeChangedSignal( "Daytime" ):Connect( function () |
07 | local attribute = script:GetAttribute( "Daytime" ) |
08 | if attribute = = true then |
18 | if timer.ClockTime > = 19 and timer.ClockTime < = 8 then |
19 | script:SetAttribute( "Daytime" , false ) |
20 | elseif timer.ClockTime < = 19 and timer.ClockTime > = 8 then |
21 | script:SetAttribute( "Daytime" , true ) |