How do I make sounds play at a specific time? I am trying to make this phone play these sounds when it turns midnight. I'm not getting any errors, but the sounds aren't playing. Like, at all. And I am also trying to get them to play at different days of the week, but I don't know if it's the day tracker on here that's messing everything up or not.
local Night = 1
while true do
wait(0.5)
if game.Lighting.ClockTime == 0 then
if Night == 1 then
script.Parent.Night1:play()
print(Night)
Night + 1
end
if Night == 2 then
script.Parent.Night2:play()
print(Night)
Night + 1
end
if Night == 3 then
script.Parent.Night3:play()
print(Night)
Night + 1
end
if Night == 4 then
script.Parent.Night4:play()
print(Night)
Night + 1
end
if Night == 5 then
script.Parent.Night5:play()
print(Night)
Night + 1
end
if Night == 6 then
print(Night)
Night + 1
end
if Night == 7 then
print(Night)
Night - 6
end
else
wait()
end
end
And here is the code for the script that changes the time.
local dayLength = 24 --How many minutes a full day(24 hours) will last
local cycleTime = dayLength*60
local minutesInADay = 24*60
local lighting = game:GetService("Lighting")
local startTime = tick() - (lighting:GetMinutesAfterMidnight()/ minutesInADay)*cycleTime
local endTime = startTime + cycleTime
local timeRatio = minutesInADay / cycleTime
if dayLength == 0 then
dayLength = 1
end
repeat
local currentTime = tick()
if currentTime > endTime then
startTime = endTime
endTime = startTime + cycleTime
end
lighting:SetMinutesAfterMidnight((currentTime - startTime)*timeRatio)
wait(1/15)
until false

2 comments
Can you show me how you are incrementing your ClockTime?
Yes