I have a Script where Music Plays during certain Times of the day. The Time changes in Studio, but doesn’t seem to be changing In Game. Does anyone know what the problem is?
My Script: (In ServerScriptService)
local Music = workspace.Engine.Music
local PartOfDay = workspace.Engine.PartOfDay
local Times = {6, 6.9, 7.8, 8.7, 9.6, 10.5, 11.4, 12.3, 13.2, 14.1, 15, 16.2, 17.1}
local CurrentTime = Times[math.random(1, #Times)]
game.Lighting:SetMinutesAfterMidnight((CurrentTime)*60)
-- DAY NIGHT
local MoveSpeed = 0.01
local ToDiv = 0.9
delay(0, function()
while true do
wait(0.25)
CurrentTime += MoveSpeed/4
game.Lighting:SetMinutesAfterMidnight((CurrentTime)*60)
if CurrentTime >= 6 and CurrentTime < 6.9 then
workspace.Engine.PartOfDay.Value = "Morning1"
elseif CurrentTime >= 6.9 and CurrentTime < 7.8 then
workspace.Engine.PartOfDay.Value = "Morning2"
elseif CurrentTime >= 7.8 and CurrentTime < 8.7 then
workspace.Engine.PartOfDay.Value = "BeforeNoon1"
elseif CurrentTime >= 8.7 and CurrentTime < 9.6 then
workspace.Engine.PartOfDay.Value = "BeforeNoon2"
elseif CurrentTime >= 9.6 and CurrentTime < 10.5 then
workspace.Engine.PartOfDay.Value = "BeforeNoon3"
elseif CurrentTime >= 10.5 and CurrentTime < 11.4 then
workspace.Engine.PartOfDay.Value = "BeforeNoon4"
elseif CurrentTime >= 11.4 and CurrentTime < 12.3 then
workspace.Engine.PartOfDay.Value = "Noon"
elseif CurrentTime >= 12.3 and CurrentTime < 13.2 then
workspace.Engine.PartOfDay.Value = "AfterNoon1"
elseif CurrentTime >= 13.2 and CurrentTime < 14.1 then
workspace.Engine.PartOfDay.Value = "AfterNoon2"
elseif CurrentTime >= 14.1 and CurrentTime < 15 then
workspace.Engine.PartOfDay.Value = "AfterNoon1"
elseif CurrentTime >= 15 and CurrentTime < 15.9 then
workspace.Engine.PartOfDay.Value = "AfterNoon2"
elseif CurrentTime >= 15.9 and CurrentTime < 16.2 then
workspace.Engine.PartOfDay.Value = "Intermission"
elseif CurrentTime >= 16.2 and CurrentTime < 17.1 then
workspace.Engine.PartOfDay.Value = "Evening1"
elseif CurrentTime >= 17.1 and CurrentTime < 18 then
workspace.Engine.PartOfDay.Value = "Evening2"
elseif CurrentTime >= 18 or CurrentTime < 6.1 then
workspace.Engine.PartOfDay.Value = "Night"
end
end
end)
PartOfDay.Changed:Connect(function(New)
if New ~= "Intermission" and New ~= "Night" then
local MusicArea = Music:FindFirstChild(New)
local ToPlay = MusicArea:GetChildren()[math.random(1, #MusicArea:GetChildren())]
ToPlay.Volume = 0.4
MoveSpeed = ToDiv/ToPlay.TimeLength
ToPlay:Play()
end
if New.Name == "Night" then
MoveSpeed = 1
end
end)
Results:
Studio:
In Game: